Skip to content

fix(scan): normalise patterns before building the AC dictionary - #59

Merged
tharindupr merged 1 commit into
c2siorg:mainfrom
VibhorGautam:fix/normalise-dead-patterns
Jul 5, 2026
Merged

fix(scan): normalise patterns before building the AC dictionary#59
tharindupr merged 1 commit into
c2siorg:mainfrom
VibhorGautam:fix/normalise-dead-patterns

Conversation

@VibhorGautam

Copy link
Copy Markdown
Contributor

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/b64
decode since those are payload-specific) and applies it at dictionary build
time. This revives 3 dead patterns:

  • jp-046 (<!-- ...): ! maps to i, so <! in the dict never matched <i in canonical text
  • jp-043 (zero-width spaces): stripZeroWidth removed U+200B from payloads but not from the dict
  • jp-038 (base64): 4 maps to a, so base64 in the dict never matched base6a in canonical text

Tests added for all 3 cases. Existing patterns are unaffected (they contain no
characters that normalise rewrites). go vet + gofmt + full suite green.

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.
@tharindupr
tharindupr merged commit f89ed10 into c2siorg:main Jul 5, 2026
2 checks passed
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.

2 participants