Skip to content

fix(query-normalize): make ERROR_SIGNAL genuinely linear-time (ReDoS hardening)#8

Merged
templetwo merged 1 commit into
mainfrom
fix/denoise-redos
Jun 18, 2026
Merged

fix(query-normalize): make ERROR_SIGNAL genuinely linear-time (ReDoS hardening)#8
templetwo merged 1 commit into
mainfrom
fix/denoise-redos

Conversation

@templetwo

Copy link
Copy Markdown
Owner

Follow-up to #7, found by the post-merge adversarial review.

lib/query-normalize.js's ERROR_SIGNAL had an unbounded leading-identifier
run ([\w$]*) before the Error|Exception|Warning suffix. On a long
suffix-less word run that forced O(n²) backtracking from every start offset
(~21s at 200K chars) — directly contradicting the file header's "linear,
ReDoS-safe by construction" claim.

Not exploitable today: the UserPromptSubmit hook caps prompts at 4000 chars
before the de-noiser runs (~10ms worst case), so fail-open held. But the lib is
exported uncapped and carried a false guarantee, and the existing "frame-flood"
test used short repeated lines that never reach the quadratic path.

Fix: bound the run to {0,64} (real exception names are far shorter) → linear.
200K worst case drops from ~21s to <100ms. Header claim corrected to "bounded
quantifiers / linear". New smoke test feeds a single 200K-char suffix-less token
under a wall-clock bound, plus a parity-at-scale check.

298 tests green (smoke 168). The decay-escalation kernel from #7 was separately
fuzzed (200k iterations) and confirmed clean — OPEN→PAUSE-only ceiling holds.

🤖 Generated with Claude Code

The leading-identifier run `[\w$]*` before the Error/Exception/Warning
suffix was unbounded, so a long suffix-less word run forced O(n^2)
backtracking from every offset (~21s at 200K chars) — contradicting the
file's own "linear, ReDoS-safe" header. Live exposure was bounded by the
4000-char prompt cap (~10ms), so this was a false-guarantee / correctness
issue, not an exploitable hang. Bound the run to {0,64} (real exception
names are far shorter) → linear; 200K worst case now <100ms.

Also corrects the header claim and adds a smoke test that feeds a single
200K-char suffix-less token under a wall-clock bound — the prior
frame-flood test used short lines and never reached the quadratic path,
so the linear-time claim was asserted but untested.

Found by the post-merge adversarial review of #7.

298 tests green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@templetwo
templetwo merged commit 812bf00 into main Jun 18, 2026
8 checks passed
@templetwo
templetwo deleted the fix/denoise-redos branch July 14, 2026 22:14
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