oasis-open / cti-python-stix2

OASIS TC Open Repository: Python APIs for STIX 2
https://stix2.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
367 stars 120 forks source link

Calling add_markings on a existing STIX object with custom properties causes an exception #126

Closed rpiazza closed 6 years ago

rpiazza commented 6 years ago

Here is the stack trace:

Traceback (most recent call last):

 File "/Users/rpiazza/projects/capec-attack/capec2stix/capec2stix.py", line 197, in <module>
    main()
  File "/Users/rpiazza/projects/capec-attack/capec2stix/capec2stix.py", line 189, in main
    tlos = convert2stix(attack_pattern_catalog, marking_def.id, ident.id)
  File "/Users/rpiazza/projects/capec-attack/capec2stix/capec2stix.py", line 170, in convert2stix
    return convert_attack_pattern(attack_pattern_catalog.Attack_Patterns.Attack_Pattern[0],  marking_def_id, ident_id)
  File "/Users/rpiazza/projects/capec-attack/capec2stix/capec2stix.py", line 158, in convert_attack_pattern
    ap.add_markings(marking_def_id)
  File "/Users/rpiazza/py-envs/python3.5/lib/python3.5/site-packages/stix2/markings/__init__.py", line 143, in add_markings
    return object_markings.add_markings(obj, marking)
  File "/Users/rpiazza/py-envs/python3.5/lib/python3.5/site-packages/stix2/markings/object_markings.py", line 40, in add_markings
    return new_version(obj, object_marking_refs=list(object_markings))
  File "/Users/rpiazza/py-envs/python3.5/lib/python3.5/site-packages/stix2/utils.py", line 234, in new_version
    return cls(**{k: v for k, v in new_obj_inner.items() if v is not None})
  File "/Users/rpiazza/py-envs/python3.5/lib/python3.5/site-packages/stix2/base.py", line 111, in __init__
    raise ExtraPropertiesError(cls, extra_kwargs)
stix2.exceptions.ExtraPropertiesError: Unexpected properties for AttackPattern: (x_capec_abstraction, x_capec_consequences, x_capec_example_instances, x_capec_likelihood_of_attack, x_capec_prerequisites, x_capec_skills_required, x_capec_typical_severity, x_resources_required).
clenk commented 6 years ago

This bug happens because we need to pass allow_custom to new_version in add_markings. I think we can assume that if we're adding markings to an object, the object has already been checked for unwanted custom properties (so we should be able to just pass allow_custom=true where we call new_version in add_markings).

Other functions that call new_version and should have the same assumption applied: