fix: evaluate regex in the subject of an association triple - #44
Open
ardittirana wants to merge 1 commit into
Open
fix: evaluate regex in the subject of an association triple#44ardittirana wants to merge 1 commit into
ardittirana wants to merge 1 commit into
Conversation
findFirstSubject built an exact content filter from the subject key and ignored its compiled regular expression, so a regex in the subject position of a triple (#/.../#) was passed through as a literal key and matched nothing. For asset types whose key is parsed (IP address, netblock, autonomous system) it failed even earlier, when subjectToAsset tried to parse the regex as a literal value. When the subject has a regular expression, fetch the entities of its type and match them in Go with valueMatch, the same way regex matching already works for the object of a triple. Adds a regression test for a regex subject. Closes owasp-amass/amass#1113
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.
What was broken
findFirstSubjectconverts the triple subject into an exact content filter viasubjectToAssetand ignores the subject's compiled regular expression. As a result, a regex in the subject position of a triple (#/.../#) is passed through as a literal key and matches nothing. For asset types whose key is parsed (IP address, netblock, autonomous system) it fails even earlier, becausesubjectToAssettries to parse the regex string as a literal value.Regex in the object position already works, because the object is matched in Go with
valueMatch.Reported in owasp-amass/amass#1113.
What changed
When the subject has a compiled regular expression,
findFirstSubjectnow fetches the entities of the subject's type and matches them in Go withvalueMatch, mirroring the object path. The existing exact-filter path is unchanged for non-regex subjects.Tests
Added
TestFindFirstSubjectRegex: it stores two IP entities, queries with a regex subject (#/^192\./#), and asserts the matching entity is returned. The test fails on current code (the regex is parsed as a literal IP and errors) and passes with this change.go build ./...,go vet ./triples/, and the fulltriplessuite pass.