Fix xss matcher catastrophic backtracking#30
Open
andymac4182 wants to merge 2 commits into
Open
Conversation
|
@andymac4182 is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
Please repush with a signed commit |
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.
What changed
Replaced the XSS matcher’s template-literal HTML regex with a small linear scanner, while keeping the existing direct DOM sink regexes. Added coverage for template interpolation mixed with HTML and for a long generated HTML/report line that previously triggered catastrophic backtracking.
Why
The previous matcher used a greedy regex:
/\$\{.*\}.*<\/?\w+>|<\w+[^>]*\$\{/That works on ordinary short source files, but it can hang on long generated lines that contain many
${...}-shaped strings without a matching HTML tag. We hit this when scanning generated report-style HTML: the regex engine spent seconds backtracking through a no-match case. This change preserves the intended XSS candidate detection while making the template-literal heuristic run in predictable linear time.Verification
pnpm testpassespnpm lintpassespnpm knippasses/Users/amcclenaghan/atlassian/nfs-restrictedtools/9p-browser-demo/index.htmlinnerHTML assignmentNotes for reviewer
The failure is input-shape dependent, which is why the old regex can appear fine on normal source files but hang on generated report artifacts. The pathological case is a long single line with many
${...}-looking strings and no eventual HTML tag match.This PR avoids the risky overlapping
.*regex entirely for the template-literal heuristic. The replacement scans each line withindexOf/character checks, so no regex backtracking is possible for that path. Existing sink detections likedangerouslySetInnerHTML,.innerHTML =,document.write, Vuev-html, and Angular[innerHTML]remain regex-based and unchanged.