Skip to content

fix: evaluate regex in the subject of an association triple - #44

Open
ardittirana wants to merge 1 commit into
owasp-amass:mainfrom
ardittirana:fix-assoc-subject-regex
Open

fix: evaluate regex in the subject of an association triple#44
ardittirana wants to merge 1 commit into
owasp-amass:mainfrom
ardittirana:fix-assoc-subject-regex

Conversation

@ardittirana

Copy link
Copy Markdown

What was broken

findFirstSubject converts the triple subject into an exact content filter via subjectToAsset and 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, because subjectToAsset tries 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, findFirstSubject now fetches the entities of the subject's type and matches them in Go with valueMatch, 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 full triples suite pass.

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
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

Successfully merging this pull request may close these issues.

1 participant