Skip to content

Fix ReDoS vulnerability#309232

Closed
tolotrasam wants to merge 6 commits intomicrosoft:mainfrom
tolotrasam:patch-1
Closed

Fix ReDoS vulnerability#309232
tolotrasam wants to merge 6 commits intomicrosoft:mainfrom
tolotrasam:patch-1

Conversation

@tolotrasam
Copy link
Copy Markdown

@tolotrasam tolotrasam commented Apr 11, 2026

In commit 87e50c6, they changed [^\[]+ → [^\[\s][^\[]\s. The PR description says [^\[]+ was overlapping with \s+. So they made the first char of the label exclude whitespace with [^\[\s]. But then [^\[]* (the rest of the label) still matches spaces, and \s* immediately follows it, same class of overlap.

This causes catastrophic backtracking on large output and leads to 100% CPU usage causing UI freezes
#307347
#306293
#305077
#307723

Fixes #307723

In commit 87e50c6, they changed [^\[]+ → [^\[\s][^\[]*\s*. The PR description says [^\[]+ was overlapping with \s+. So they made the first char of the label exclude whitespace with [^\[\s]. But then [^\[]* (the rest of the label) still matches spaces, and \s* immediately follows it, same class of overlap.
Copilot AI review requested due to automatic review settings April 11, 2026 23:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates a regex used by the terminal chat agent’s output monitoring logic (detectsInputRequiredPattern) to address a potential ReDoS/backtracking issue when detecting PowerShell-style multi-option prompts.

Changes:

  • Tightens the “PowerShell-style multi-option line” detection regex by excluding whitespace from the option label match.

// PowerShell-style multi-option line (supports [?] Help and optional default suffix) ending
// in whitespace
/\s*(?:\[[^\]]\]\s+[^\[\s][^\[]*\s*)+(?:\(default is\s+"[^"]+"\):)?\s+$/,
/\s*(?:\[[^\]]\]\s+[^\[\s][^\[\s]*\s*)+(?:\(default is\s+"[^"]+"\):)?\s+$/,
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

The PR description notes that the change was only to exclude whitespace for the first label character while allowing spaces later ([^\[\s][^\[]*\s*). The current regex also excludes whitespace for the rest of the label ([^\[\s]*), which changes matching semantics for multi-word labels. Consider updating the PR description to reflect the actual change (or adjusting the regex if multi-word labels must remain supported).

Copilot uses AI. Check for mistakes.
@tolotrasam
Copy link
Copy Markdown
Author

@meganrogge @rducom

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@meganrogge meganrogge added this to the 1.117.0 milestone Apr 13, 2026
@meganrogge
Copy link
Copy Markdown
Collaborator

Thanks for looking into this @tolotrasam! The ReDoS diagnosis is spot on.

I pushed a commit to your branch that adjusts the fix slightly — the [^\[\s]* replacement breaks multi-word PowerShell labels like "Yes to All" and "No to All" (there are existing tests for these). The updated regex uses [^\[\s]+(?:\s+[^\[\s]+)* instead, which matches multi-word labels while still eliminating the overlap with \s* that caused the backtracking. I also added a regression test with pathological input to guard against future regressions.

@meganrogge meganrogge enabled auto-merge (squash) April 13, 2026 20:42
@tolotrasam
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@tolotrasam
Copy link
Copy Markdown
Author

Hi @meganrogge — looks like the regex fix from this PR was included in commit b97c65a (PR #309611) that was merged to main. Could a Co-authored-by: tolotrasam <tolotrasam@gmail.com@users.noreply.github.com> trailer be added to the squash commit? I identified the remaining ReDoS overlap and submitted the initial fix here.

Happy to close this PR since the fix is already on main. Thanks!

@meganrogge
Copy link
Copy Markdown
Collaborator

Yes! I will add that to #310145, which is another regex fix 😅

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.

[Copilot Agent Autopilot] VS Code Insiders completely freezes ("The window is not responding") when agent runs GitHub CLI commands

5 participants