Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STIX 2.1 File observable bug #296

Closed
chisholm opened this issue Oct 4, 2019 · 0 comments
Closed

STIX 2.1 File observable bug #296

chisholm opened this issue Oct 4, 2019 · 0 comments

Comments

@chisholm
Copy link
Contributor

chisholm commented Oct 4, 2019

To reproduce:

import stix2
stix2.parse_observable({'atime': '2019-06-28T17:53:32Z',
   'contains_refs': ['domain-name--936999fe-d6c1-4838-aa8a-6f3acc5eea1f',
                   'autonomous-system--f3e0df99-a173-48ac-be87-4bad2945b499',
                   'windows-registry-key--077e6e5e-a7d2-4191-acf3-d5a4c83553bf',
                   'mutex--c136aeaf-d520-467f-8fbc-357d5e7b8b3c',
                   'mac-addr--ba103e76-68d8-4efc-b337-a3173f3dc087'],
 'id': 'file--0a41e9b1-640a-4d48-bf3c-57ace6b07c38',
 'mime_type': 'video/ogg',
 'mtime': '2018-11-14T16:20:24Z',
 'name': 'majority.avi',
 'parent_directory_ref': 'directory--f30f0714-4f59-492b-8cd6-8ea08e07bd6f',
 'type': 'file'}, version="2.1")

Exception:

Traceback (most recent call last):
  File "C:\Programming\python\stix\cti-python-stix2\stix2\base.py", line 94, in _check_property
    kwargs[prop_name] = prop.clean(kwargs[prop_name])
  File "C:\Programming\python\stix\cti-python-stix2\stix2\properties.py", line 180, in clean
    valid = self.contained.clean(item)
  File "C:\Programming\python\stix\cti-python-stix2\stix2\properties.py", line 472, in clean
    _validate_id(value, self.spec_version, required_prefix)
UnboundLocalError: local variable 'required_prefix' referenced before assignment

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 12, in <module>
  File "C:\Programming\python\stix\cti-python-stix2\stix2\core.py", line 172, in parse_observable
    return obj_class(allow_custom=allow_custom, **obj)
  File "C:\Programming\python\stix\cti-python-stix2\stix2\base.py", line 324, in __init__
    super(_Observable, self).__init__(**kwargs)
  File "C:\Programming\python\stix\cti-python-stix2\stix2\base.py", line 177, in __init__
    self._check_property(prop_name, prop_metadata, setting_kwargs)
  File "C:\Programming\python\stix\cti-python-stix2\stix2\base.py", line 356, in _check_property
    super(_Observable, self)._check_property(prop_name, prop, kwargs)
  File "C:\Programming\python\stix\cti-python-stix2\stix2\base.py", line 104, in _check_property
    exc,
  File "<string>", line 3, in raise_from
stix2.exceptions.InvalidValueError: Invalid value for File 'contains_refs': local variable 'required_prefix' referenced before assignment

I think the cause is the way the contains_refs property is defined:

('contains_refs', ListProperty(ReferenceProperty(invalid_types="", spec_version='2.1'))),

invalid_types is assigned the empty string. That means in the ReferenceProperty object, both self.valid_types and self.invalid_types are "falsey": the former is None and the latter is the empty string. That means both branches of the if statement in the clean() method are skipped, which means required_prefix is never assigned a value. That causes the UnboundLocalError when it's used in _validate_id().

@clenk clenk closed this as completed in aee296e Dec 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant