fix(helpers): escape literal . in ASCII-section regex - #7476
Conversation
`highlightAsciiSection` built a regex like `(.\n*)(.\n*)` for every non-printable byte in a matcher snippet, intending the `.` as the literal character hex.Dump puts in the ASCII column. The regex engine treated it as "any char". On the first pass this over-highlights every character in the row; on the second highlight pass (when more than one matcher hit), the now ANSI-coloured row is full of 2-character fragments like "\x1b[", "32", "0m" that all match. Each strings.ReplaceAll in the highlight loop then inflates the buffer 3-10x, producing exponential growth that pegs CPU and OOMs the process within seconds. Triggered by any TCP/network template with >=2 binary matchers of different lengths over a response containing non-printable bytes, run with -debug / -debug-resp / -store-resp. Adds a regression test that fails (hangs >5s) on the bug and passes in <10ms with the fix.
WalkthroughA one-character regex fix in ChangesHex dump regex catastrophic backtracking fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Reviewed this PR. Assessment: Implementation looks solid and follows project conventions. Clean code quality. Approved ✅ |
. in ASCII-section regex. in ASCII-section regex
|
Thank you for your contributions, @snicket2100! Merging this. |
Fixes #7475.
Fixes an exponential-blowup bug in
responsehighlighter.highlightAsciiSectionthat hangs nuclei and OOMs the process within seconds whenever debug output is enabled for a network template whose matched response contains non-printable bytes, AND ≥2 matched binary fragments end up inOperatorsResult.Matches.Proof
Steps to reproduce from #7475 don't longer result in
nucleientering an infinite loop.Checklist
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests