fix(cli): split trailing punctuation off redacted URLs in linear time - #2541
Merged
Merged
Conversation
redactUrlsInText stripped a URL's trailing sentence punctuation with the unanchored regex /[.,;:!?)\]']+$/, which rescans a punctuation run from every start position when the run does not end the match: quadratic. The text is server-controlled (an HTTP error body lands in the error message), so a body of http://a/? plus a long run of '!' before an 'x' stalled the CLI's error path: 60k characters took 3s, against 0s on 2.8.0. CodeQL flagged it high on the v2.9.0 merge PR (#2536). Replace it with a backward scan over the same character set. Behavior is unchanged; the same probe now answers in ~180ms at 60k and at 400k. Closes #2540 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The linear scan preserves existing suffix behavior and the regression test covers the reported adversarial input.
Review effort: Balanced
Findings: None
What changed in this PR
Replaces a quadratic URL trailing-punctuation regex in the CLI error-redaction path with a behavior-equivalent linear scan.
Changes:
- Adds a backward punctuation scan using a character set.
- Adds regression coverage for a 50,000-character server-controlled punctuation run.
| File | Description |
|---|---|
clients/cli/src/error-handler.ts |
Implements linear trailing-punctuation detection. |
clients/cli/__tests__/error-handler.test.ts |
Tests long embedded punctuation while preserving secret redaction. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Member
Author
|
Copilot review loop closed: round 1 was clean (approval recommended, no findings, no inline or suppressed comments), so no further round was requested. |
This was referenced Sep 30, 2026
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.
Closes #2540
CodeQL flagged this on the v2.9.0 milestone-merge PR (#2536): "Polynomial regular expression used on uncontrolled data", high severity, at
clients/cli/src/error-handler.ts:169.Problem
redactUrlsInText(added for #2423 in PR #2488) split a URL's trailing sentence punctuation off with the unanchored/[.,;:!?)\]']+$/. When a punctuation run does not end the match, the engine rescans it from every start position, which is quadratic. The text is server-controlled: the CLI copies an HTTP error body into the error message.see http://a/?…+ n ×!+x)The regex alone: 5k → 17 ms, 10k → 61 ms, 20k → 238 ms, 40k → 857 ms.
Fix
A backward scan over the same character set (
trailingPunctuationStart) replaces the regex. Behavior is unchanged, and every existing redaction case still passes: the kept full stop, the single-quoted URL, the apostrophe inside a value, comma-joined URLs, and mixed-case schemes. Redaction still holds at both probe sizes:code=%5BREDACTED%5D, 0 secret hits.Tests
clients/cli/__tests__/error-handler.test.tsadds a 50,000-character punctuation run inside a URL. Only the trailing!?is split off, and the secret parameter after the run is still redacted.Verification
npm run format→ cleannpm run local:gate→ green (exit 0, 5m07s)🤖 Generated with Claude Code