Skip to content

fix(tools): strip trailing dots in spinner messages without a regex - #745

Merged
thiagobrez merged 1 commit into
mainfrom
fix/tools-start-message-redos
Nov 5, 2026
Merged

thiagobrez merged 1 commit into
mainfrom
fix/tools-start-message-redos

Conversation

@thiagobrez

Copy link
Copy Markdown
Collaborator

Summary

Fixes CodeQL alert #5 (js/polynomial-redos, high) in packages/tools/src/lib/prompts.ts. It has been open on main since March.

formatStartMessage stripped trailing dots with text.replace(/\.+$/, ''). On a string with a long run of dots followed by something else, the regex engine retries \.+ from every position, so the time grows quadratically: about 3 s for 100k dots and 13 s for 200k. The input is a spinner message, so this isn't exploitable in practice. But the alert fails the CodeQL check on any PR that touches a line in its data flow. For example, #744 fails only because it changes the packageAar signature, where CodeQL says the regex's input comes from.

This PR replaces the regex with a loop that walks back over trailing dots. The output is unchanged for every input.

Test plan

  • New prompts.test.ts: covers no dots, one dot, three dots, a dot mid-string, only dots, an empty string and undefined, plus a 200k-dot regression case. Against the old regex, the regression case takes 13.5 s and fails the 5 s timeout; with the fix all 8 tests pass in about 1 ms.
  • eslint, prettier and tsc -p packages/tools/tsconfig.lib.json are clean.

@vercel

vercel Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
rock Ignored Ignored Nov 4, 2026 3:03pm UTC

Request Review

@andrei-zgirvaci andrei-zgirvaci left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job! LGTM!

@thiagobrez
thiagobrez merged commit cb08140 into main Nov 5, 2026
9 checks passed
@thiagobrez
thiagobrez deleted the fix/tools-start-message-redos branch November 5, 2026 12:00
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.

3 participants