Fix granular marking selectors for nested STIX sub-objects (#585)#644
Open
arpitjain099 wants to merge 1 commit into
Open
Fix granular marking selectors for nested STIX sub-objects (#585)#644arpitjain099 wants to merge 1 commit into
arpitjain099 wants to merge 1 commit into
Conversation
iterpath only recursed into dict values, but STIX sub-objects like ExternalReference are collections.abc.Mapping instances and not dict subclasses, so selectors such as external_references.[0].source_name were never generated and validation rejected them. Switch the two type checks in iterpath to collections.abc.Mapping. Fixes oasis-open#585. Signed-off-by: arpitjain099 <arpitjain099@gmail.com>
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.
Adding a granular marking with a selector that points into a STIX sub-object gets rejected even when the selector is valid. For example the STIX 2.1 spec (7.2.3.1) uses
external_references.[0].source_name, butadd_markings(TLP_GREEN, "external_references.[0].source_name")raisesInvalidSelectorError.The cause is in
iterpathin stix2/markings/utils.py: it only recurses when a value is adict, but STIX sub-objects like ExternalReference arecollections.abc.Mappinginstances and notdictsubclasses, so the nested path is never generated and validation then treats the valid selector as invalid. This switches the two type checks tocollections.abc.Mapping.Added a regression test in test_granular_markings.py that marks
external_references.[0].source_name; it fails on master and passes with this change, and the existing v20/v21 marking tests still pass. Fixes #585.