Repository navigation
fix(typescript): eliminate ReDoS in chat parser role-boundary regex - #480
Merged
Seth Juarez (sethjuarez) merged 1 commit intoAug 18, 2026
Merged
Conversation
The role-boundary regex nested a repetition whose value class overlapped the `\w+=` iteration starter and the separators, so a long attribute run (e.g. `name=aname=a...`) could be partitioned exponentially, causing catastrophic backtracking. JavaScript has no possessive quantifiers (unlike the Python fix in #457), so the nested `+` is removed: the bracket now requires an attribute-like start and swallows the remainder with a single non-overlapping `[^]]*` class, which is structurally linear. Individual attributes are still split by ATTR_RE, so behavior is preserved. Adds a bounded-runtime regression test and a multi-unquoted-attribute test. Fixes #446 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Seth Juarez (sethjuarez)
deleted the
sejuare-microsoft/fix-ts-parser-redos
branch
August 18, 2026 05:05
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.
Summary
Eliminates a ReDoS (catastrophic backtracking) vulnerability in the TypeScript chat parser's role-boundary regex — the TypeScript half of #446. The Python half was fixed in #457.
The bug
The old boundary regex nested a repetition whose value class overlapped both the
\w+=iteration starter and the separators:A long attribute-like run with no valid terminator (e.g.
user[name=aname=a...name=a") can be partitioned exponentially, so the engine hangs. I confirmed this locally: the adversarial input did not terminate.The fix
JavaScript's
RegExphas no possessive quantifiers or atomic groups (so the Python 3.11 approach in #457 doesn't port). Instead the nested+is removed entirely: the bracket now requires an attribute-like start and swallows the remainder of the bracket with a single, non-overlapping class:This is structurally linear (verified: 40,000-repetition adversarial input matches in ~0.2ms). Individual attributes are still split by the unchanged
ATTR_RE, so parsing behavior is preserved — including multi-attribute lines likeuser[name=Bob, id=7]:and quoted commas likeuser[name="a,b"]:. Parity holds for negatives too (user[garbage]:is still not a boundary).Tests
< 1000mson adversarial input).user[name=Bob, id=7]:).tsc --noEmitclean.Fixes #446