Repository navigation
Description
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
MatIcon._prependPathToReferences() interpolates location.pathname + location.search into a single-quoted CSS url('…') value:
element.setAttribute(attr.name, `url('${normalizedPath}#${attr.value}')`);A literal ' is preserved in an HTTP(S) pathname, so a path containing one closes that string early and the remainder of the path is parsed as further CSS tokens in the attribute. mask and filter accept a list of references, so those extra tokens become additional references rather than being ignored, and one of them can resolve to another origin.
#33812 made the value root-relative for paths beginning with //. It does not escape the value, so this case is not covered by it.
Reproduction
A StackBlitz reproduction is not possible for this one: the input is location.pathname, and the StackBlitz preview host does not allow serving the app under an arbitrary path containing a '. Minimal local reproduction instead:
ng new demo && cd demo && npm i @angular/material @angular/cdk- Register an icon that uses a
maskreference and render it with<mat-icon svgIcon="cover"></mat-icon>:
registry.addSvgIconLiteral('cover', sanitizer.bypassSecurityTrustHtml(
'<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48">' +
'<defs><mask id="cover"><circle cx="24" cy="24" r="24" fill="white"/></mask></defs>' +
'<rect width="48" height="48" fill="#1a73e8" mask="url(#cover)"/></svg>'));- Build it and serve
index.htmlfor any request path (a standard SPA history fallback). - Open the app at
/safe'),url('https://other.example/x - Inspect the rendered
rect'smaskattribute.
The parsing half can also be seen without an app, which is what makes the impact concrete. In Chrome:
const el = document.createElement('div');
el.style.maskImage = `url('/safe'),url('https://other.example/x#cover')`;
el.style.maskImage;
// => url("/safe"), url("https://other.example/x#cover") — two referencesWith the quote escaped, the same value parses as a single reference on the current origin.
Expected Behavior
The rewritten attribute always contains exactly one reference, resolving to the current origin, whatever characters the current path happens to contain.
Actual Behavior
The attribute can contain more than one reference. With the path above, the rendered mask becomes:
url('/safe'),url('https://other.example/x#cover')
which Chrome parses as two references, the second one pointing at another origin. With a quote-free path the attribute is unchanged, so only paths containing ' (or \) are affected.
Environment
Angular: 22.x
@angular/cdk, @angular/material: 22.2.2 (the same code is present on main)
Browser: Chrome (current)
Node: 22.x
OS: any
Activity