fix(platform-browser): prevent ReDoS in SOURCEMAP_URL_REGEXP#69763
Merged
Conversation
Replace the lazy quantifier (.+?) with a negated character class ([^\s*]+) that excludes whitespace and asterisks. Source map URLs never contain these characters, so the fix is semantically equivalent while eliminating the O(n²) backtracking path triggered by unclosed /*# sourceMappingURL= fragments. Fixes: polynomial ReDoS in addBaseHrefToCssSourceMap
JeanMeche
approved these changes
Jul 14, 2026
Member
|
Note: while this is a ReDos fix, I wouldn't consider this a security fix.
|
Member
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.
Problem
SOURCEMAP_URL_REGEXPin@angular/platform-browseruses a lazy quantifier (.+?) that causes polynomial O(n²) backtracking when CSS contains unclosed/*# sourceMappingURL=fragments.When
kunclosed fragments exist in a CSS string of lengthL, each fragment at positionicosts O(L − i) steps, giving O(k × L) = O(L²) total — a classic ReDoS pattern.Impact on Angular SSR / Universal:
addBaseHrefToCssSourceMapis called server-side on every render request for components that have a non-emptybaseHref. At k=2000 fragments (~48 KB CSS), a single call blocks the Node.js event loop for ~71 ms, enabling event-loop saturation under moderate traffic.Benchmark (Node.js 24 / V8):
10× input → ~54× time → O(n²) confirmed.
Fix
Replace the lazy quantifier with a negated character class that excludes whitespace and
*. Source map URLs never contain either character, so the fix is semantically equivalent.Testing
Verified against the published
@angular/platform-browser@22.0.4npm bundle (fesm2022/_dom_renderer-chunk.mjs).Related
Reported to Google OSS VRP — referred to Angular GitHub for fix.