Repository navigation
fix: let custom ATT&CK objects serialize through stix2 - #256
Open
frostyhand wants to merge 1 commit into
Open
frostyhand wants to merge 1 commit into
frostyhand wants to merge 1 commit into
Conversation
CustomStixObject.serialize() was a placeholder that raised NotImplementedError. The @CustomObject decorator puts CustomStixObject ahead of the stix2 base class in the MRO, so the placeholder hid the real serialize(). str(), print() and MitreAttackData.print_stix_object() failed for every matrix, tactic, data source, data component, asset, analytic and detection strategy. Keep the method for type hints but pass the call on to stix2. Fixes mitre-attack#207
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #207
print(),str(),.serialize()andMitreAttackData.print_stix_object()fail for every ATT&CK custom object (matrix, tactic, data source, data component, asset, analytic, detection strategy) with:Cause
CustomStixObject.serialize()was added as a placeholder with the type hints in 5d4b16c. The@CustomObjectdecorator builds each class as_CustomObject(DataComponent, _DomainObject), so the method resolution order isDataComponent -> CustomStixObject -> _DomainObject -> _STIXBase20. The placeholder sits ahead of stix2's realserialize()and hides it._STIXBase.__str__callsserialize(), which is why a plainprint(obj)fails too.On the current Enterprise ATT&CK bundle, none of these objects can be printed on
main: 0 of 109 data components, 15 tactics, 1 matrix, 38 data sources, 1,773 analytics and 708 detection strategies.Fix
Keep the method so type hints still see
serialize()onCustomStixObject, but pass the call on to stix2 withsuper().serialize(*args, **kwargs). The arguments are the same as stix2's, soserialize(pretty=True), the positionalserialize(True)used byprint_stix_object, andsort_keysand friends all work.Tests
test_custom_objects_serializecovers all seven custom classes: compact and pretty output, the positional form, andstr(). All 7 cases fail onmain.ruff checkandruff format --checkare clean.print_stix_objectprints a tactic as pretty JSON.