fix(scan): normalise patterns before building the AC dictionary - #59
Merged
Merged
Conversation
The Aho-Corasick dictionary was built from raw pattern text while payloads go through NFKC, zero-width stripping, and leetspeak cleaning. Patterns containing characters that normalise rewrites could never match. Add normalisePattern and apply it at dictionary build time so the AC alphabet matches CanonicalText. Fixes jp-046, jp-043, jp-038.
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.
The AC dictionary in NewScanStage was built from raw pattern strings, but
CanonicalText goes through NFKC, zero-width stripping, and leetspeak cleaning
in the normalise stage. Any pattern containing characters that those transforms
rewrite could never match because the dictionary and the searched text used
different alphabets.
Adds
normalisePattern(NFKC + stripZeroWidth + cleanLeetspeak, no URL/b64decode since those are payload-specific) and applies it at dictionary build
time. This revives 3 dead patterns:
<!-- ...):!maps toi, so<!in the dict never matched<iin canonical textstripZeroWidthremoved U+200B from payloads but not from the dictbase64):4maps toa, sobase64in the dict never matchedbase6ain canonical textTests added for all 3 cases. Existing patterns are unaffected (they contain no
characters that normalise rewrites). go vet + gofmt + full suite green.