fix(query-normalize): make ERROR_SIGNAL genuinely linear-time (ReDoS hardening)#8
Merged
Conversation
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>
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.
Follow-up to #7, found by the post-merge adversarial review.
lib/query-normalize.js'sERROR_SIGNALhad an unbounded leading-identifierrun (
[\w$]*) before theError|Exception|Warningsuffix. On a longsuffix-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