Skip to content

fix(platform-browser): prevent ReDoS in SOURCEMAP_URL_REGEXP#69763

Merged
mattrbeck merged 1 commit into
angular:mainfrom
CYANO-01:fix/redos-sourcemap-url-regexp
Jul 14, 2026
Merged

fix(platform-browser): prevent ReDoS in SOURCEMAP_URL_REGEXP#69763
mattrbeck merged 1 commit into
angular:mainfrom
CYANO-01:fix/redos-sourcemap-url-regexp

Conversation

@CYANO-01

Copy link
Copy Markdown
Contributor

Problem

SOURCEMAP_URL_REGEXP in @angular/platform-browser uses a lazy quantifier (.+?) that causes polynomial O(n²) backtracking when CSS contains unclosed /*# sourceMappingURL= fragments.

// Before (vulnerable):
const SOURCEMAP_URL_REGEXP = /\/\*#\s*sourceMappingURL=(.+?)\s*\*\//;

When k unclosed fragments exist in a CSS string of length L, each fragment at position i costs O(L − i) steps, giving O(k × L) = O(L²) total — a classic ReDoS pattern.

Impact on Angular SSR / Universal: addBaseHrefToCssSourceMap is called server-side on every render request for components that have a non-empty baseHref. 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):

k (fragments) CSS length Time
100 2 400 chars 0.31 ms
500 12 000 chars 4.26 ms
1 000 24 000 chars 16.55 ms
2 000 48 000 chars 71.15 ms

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.

// After (O(n), safe):
const SOURCEMAP_URL_REGEXP = /\/\*#\s*sourceMappingURL=([^\s*]+)\s*\*\//;

Testing

Verified against the published @angular/platform-browser@22.0.4 npm bundle (fesm2022/_dom_renderer-chunk.mjs).

Related

Reported to Google OSS VRP — referred to Angular GitHub for fix.

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
@pullapprove
pullapprove Bot requested a review from kirjs July 14, 2026 02:24
@angular-robot angular-robot Bot added the area: core Issues related to the framework runtime label Jul 14, 2026
@ngbot ngbot Bot added this to the Backlog milestone Jul 14, 2026
@JeanMeche
JeanMeche removed the request for review from kirjs July 14, 2026 10:07
@JeanMeche

Copy link
Copy Markdown
Member

Note: while this is a ReDos fix, I wouldn't consider this a security fix.

  • addBaseHrefToCssSourceMap is guarded by a devmode flag
  • This would really be an issue with JIT, as even if a server was accidentally run in development mode, an attacker cannot exploit this. The input being fed into the regex is component styles which is the static CSS defined by the developer in the @Component({ styles: [...] }) decorator at compile time.

@JeanMeche JeanMeche added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Jul 14, 2026
@mattrbeck
mattrbeck merged commit fb6b354 into angular:main Jul 14, 2026
26 of 28 checks passed
@mattrbeck

Copy link
Copy Markdown
Member

This PR was merged into the repository. The changes were merged into the following branches:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants