Title: SVG `
Open Graph Title: SVG `
X Title: SVG `
Description: Which @angular/* package(s) are the source of the bug? core / compiler Is this a regression? No Description SECURITY_SCHEMA registers one attribute for the SVG namespace, on (dom_security_schema.ts#L106): registerContext(SecurityCont...
Open Graph Description: Which @angular/* package(s) are the source of the bug? core / compiler Is this a regression? No Description SECURITY_SCHEMA registers one attribute for the SVG namespace, on (dom_security_schem...
X Description: Which @angular/* package(s) are the source of the bug? core / compiler Is this a regression? No Description SECURITY_SCHEMA registers one attribute for the SVG namespace, on <a> (dom_security...
Opengraph URL: https://github.com/angular/angular/issues/71618
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"SVG `\u003cuse>` `href` bindings bypass sanitization allowing XSS","articleBody":"### Which @angular/* package(s) are the source of the bug?\n\ncore / compiler\n\n### Is this a regression?\n\nNo\n\n### Description\n\n\n`SECURITY_SCHEMA` registers one attribute for the SVG namespace, on `\u003ca>` ([`dom_security_schema.ts#L106`](https://github.com/angular/angular/blob/v22.2.3/packages/compiler/src/schema/dom_security_schema.ts#L106)):\n\n```ts\nregisterContext(SecurityContext.URL, SVG_NAMESPACE, [['a', ['href', 'xlink:href']]]);\n```\n\n`use` is not there, so `securityContext(':svg:use', 'href', true)` lands on `checkSecurityContext('use', 'href', 'svg')` and returns `SecurityContext.NONE`, and `'xlink:href'`\nresolves through the same lookup to the same thing. The compiler emits `ɵɵattribute` with the sanitizer slot empty, and its own checked-in golden uses this element and shows it\n([`namespace_attr.js#L7`](https://github.com/angular/angular/blob/v22.2.3/packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/elements/namespace_attr.js#L7)):\n\n```js\n$r3$.ɵɵattribute('href', ctx.value, null, 'xlink');\n// ^^^^ the sanitizer argument\n```\n\n`\u003cuse href>` fetches a document and clones it into the page, and handlers and hyperlinks in that clone are live, so the attribute does what `iframe[src]`, `object[data]` and `embed[src]` do. Those three are `RESOURCE_URL`. That one missing schema entry is the whole defect, and since every spelling of the binding fails through the same lookup, one entry fixes all of them.\n\nA dangerous form is the one where the bound value reaches the document part of the URL, and `[attr.href]` / `[attr.xlink:href]` is the only way to bind this attribute, so there is no other syntax an application can move to.\n\n**Route A, a `data:` URL in any field the app binds.** An\nattacker's: one stored text field that the app later binds is the entire vector.\n\n```html\n\u003c!-- iconUrl = 'data:image/svg+xml;base64,' + btoa(profile.icon) + '#x' -->\n\u003csvg>\u003cuse [attr.href]=\"iconUrl\">\u003c/use>\u003c/svg>\n```\n\nIt executed on Chrome 116 and on Firefox 104 to 121, and on Chrome 113, 114 and 115, with\n15, 20 and 16 hits out of 24 launches against 24 of 24 on 116. I bound it as a literal string and as one\nbuilt with `btoa()` at runtime, with the same result. On WebKit no `data:` URL reached the document in 30\nspellings and the `\u003cuse>` box stayed 0x0, so there the refusal is at the load and not at the handler.\n\n**Route B, bytes at a URL on the app's own origin.** Two ways to put them there, an upload the app serves\nback or any endpoint whose response parses as XML and carries the attacker's `\u003csvg>` somewhere inside it:\n\n```html\n\u003csvg>\u003cuse [attr.href]=\"iconUrl\">\u003c/use>\u003c/svg>\n\u003c!-- iconUrl = '/uploads/avatar.png#x' -->\n\u003csvg>\u003cuse [attr.xlink:href]=\"iconUrl\">\u003c/use>\u003c/svg>\n\u003c!-- the more common spelling in real code -->\n\u003csvg>\u003cuse [attr.href]=\"apiUrl\">\u003c/use>\u003c/svg>\n\u003c!-- apiUrl = '/api/profile.xml#x', no upload -->\n\u003csvg>\u003cuse [attr.href]=\"assetUrl\">\u003c/use>\u003c/svg>\n\u003c!-- assetUrl = '/asset.svg', WebKit from 26.5 -->\n```\n\n`\u003cuse>` resolves the fragment to an element id, so the response does not have to be an SVG file. 9 of the 12 envelopes I served through the app's own `/api/profile.xml` ran on Chrome 121, and the same 9 onWebKit: a feed, a SOAP body, a sitemap, an XML API response, an XHTML page, a record list, an `\u003c?xml?>`prologue, bytes after the root element, and the `\u003csvg>` four levels deep in an unrelated namespace. Firefox 156 stops at the trailing bytes, so it ran 8; a JSON envelope, bytes before the root and no\n`xmlns` never ran.\n\nRoute B needs from that response is the follow Same-origin, with or without CORS, and a 2xx status, on every engine.\n\nChrome and Firefox also require an XML or SVG media type and a fragment in the URL. WebKit never checks the media type: the same bytes run as `image/png`, `text/plain`,\n`application/octet-stream` and `text/html`, which are the four a team picks on purpose to be safe. And from 26.5 it needs no fragment either, which is the fragmentless shape above. `Content-Disposition: attachment`, `X-Content-Type-Options: nosniff`, a `.png` path and a CSP on the response itself change nothing anywhere, and that is the usual \"serve user uploads safely\" configuration, the default in Rails ActiveStorage proxy mode and Django `FileResponse(as_attachment=True)`. On WebKit nothing on the response blocks it, and the only control left is serving uploads from another origin.\n\nBy browser build:\n\n| Browser | Route A | Route B |\n| ---------------- | ------- | ---------------------- |\n| Chrome 113–115 | yes | no |\n| Chrome 116 | yes | yes |\n| Chrome 117–121 | no | yes |\n| Chrome 122–158 | no | no, the sprite renders |\n| Firefox 104–121 | yes | yes |\n| Firefox 122–159 | no | yes |\n| WebKit 16.0–27.2 | no | yes |\n\nFirefox still runs Route B, and Mozilla closed [bug 1912763](https://bugzilla.mozilla.org/show_bug.cgi?id=1912763) as INVALID because these handlers only run when everything is same-origin, which an app serving user SVG from its own origin is.\n\nTwo things in the clone are a different mechanism rather than another route. The cloned `\u003ca>` is not a handler at all but a live hyperlink, so `\u003ca href=\"javascript:\">` runs on a trusted click on Chrome **115 and 122**, where every handler sink is inert, which puts its window at 115 to 122 rather than 116 to 121. And `\u003cforeignObject>\u003cdetails open=\"open\" ontoggle>` fires with **no interaction and no resource load**, which is what defeats stripping `on*` from uploads or refusing `\u003cimage>`.\n\n\n### Please provide a link to a minimal reproduction of the bug\n\nSee https://github.com/SkyZeroZx/ng-bypass-svg-xss\n\nYou can run \n\n```bash\nnpm install\nnpm run fixtures\nnpm run matrix -- --angular 22 --chrome 121 --firefox 121 --suite floor\nnpm run matrix -- --angular 22 --chrome 121 --suite xml\n```\n\n### Please provide the environment you discovered this bug in (run `ng version`)\n\n```true\nAngular: 20.3.34, 21.2.25, 22.2.3\nNode: 24.16.0\nOS: Windows 11 x64\n\nChrome for Testing 113–123, 125, 130, 135, 140, 145, 150, 155–158; Chromium 107–116, 121, 122\nFirefox 104, 112, 115, 117–123, 133, 138, 143, 148, 153, 156, 159; ESR 115, 140, 153\nWebKit 16.0 to 27.2, 19 Playwright builds over 11 versions (not Safari itself)\n```\n\n### Anything else?\n\nAll tests were performed on Windows, so I can't give a completely reliable guarantee for Safari. I believe the WebKit validation should be relatively reliable, and I would appreciate it if someone could validate it manually. (I have validated this completely manually in both Chrome and Firefox.)","author":{"url":"https://github.com/SkyZeroZx","@type":"Person","name":"SkyZeroZx"},"datePublished":"2026-10-26T04:58:13Z","url":"https://github.com/angular/angular/issues/71618"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:883540d4-d879-e94b-80bd-3666ee853b8d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B78C:2D2F2F:181ED41:1EE54D4:6B012F70 |
| html-safe-nonce | 0cb48cc49bd4bdd6c990aada08e18fa674a7abe0ae87f9ccc33dcaa697b18779 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNzhDOjJEMkYyRjoxODFFRDQxOjFFRTU0RDQ6NkIwMTJGNzAiLCJ2aXNpdG9yX2lkIjoiNjgyOTMxOTU4ODExMTUyNzc5MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 786752aff5a783411f93b04c84b2ff5250dc84daf14f3752458a0fba47f618a2 |
| hovercard-subject-tag | issue:6033631349 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/71618/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5171480ba256d3d59b6f015e24e289a784a4a7cb474c32eb847125515958d437/angular/angular/issues/71618 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5171480ba256d3d59b6f015e24e289a784a4a7cb474c32eb847125515958d437/angular/angular/issues/71618 |
| og:image:alt | Which @angular/* package(s) are the source of the bug? core / compiler Is this a regression? No Description SECURITY_SCHEMA registers one attribute for the SVG namespace, on (dom_security_schem... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | SkyZeroZx |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width