-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add SVG <use> href attribute to Trusted Types enforcement #357
Comments
Prehaps |
Don't forget that the |
This vector using regular let attackerControlledString = "data:image/svg+xml,<svg id='x' xmlns='http://www.w3.org/2000/svg'><image href='1' onerror='console.log(/direct/,origin)' /></svg>#x";
const svg=document.createElementNS("http://www.w3.org/2000/svg", "svg");
const use=document.createElementNS("http://www.w3.org/2000/svg", "use");
use.setAttribute('href', attackerControlledString);
svg.appendChild(use);
document.body.appendChild(svg); To make sure I understand the root cause: These vectors are dynamically setting the According to the <use href> in SVG spec though:
I wonder why data: URLs are processed in the first place (they are cross-origin), i.e. is https://portswigger.net/web-security/cross-site-scripting/cheat-sheet#data-url-with-use-element an implementation bug? I could not find anything about this in Chromium bug tracker. @mozfreddyb, do you recall anything about loading |
What does that even mean? Is a "cloned document" a navigation? The details in use-element shadow tree for navigation/fetching are quite vague on this, but I think they ought to be "nested browsing contexts" @koto: Would you be interested in collecting usage metrics for |
Fwiw, @annevk made the very good point that the URL scheme might just not matter and e.g., http://html5sec.org/test.svg could also just work? |
No, at least in Blink implementation this is blocked. From what I can tell so far, Blink is just Fetching with mode |
|
No it wouldn't. Mode has to be "cors" to allow CORS. (It's not clear that alone is a sufficient argument though as the natural extension for cross-origin resources here would be to allow that, just like we've done in other places.) |
https://jsbin.com/nolivug/2/edit?html,console tries |
FWIW, SVG would like |
I think |
I don't follow, care to elaborate? |
While above won't work in Chrome, but you can use iframe with name attribute to steal nonce in Chrome too (which is by design). The concerning point with cross-origin resource in |
The attribute contains a URL that points to an SVG fragment to be loaded and presented inside the element. The URL can additionally contain a URL fragment representing the ID of a particular element to fetch from within that fragment. See https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#iri for details, and w3c/trusted-types#357 for the associated security risks. A common development pattern is to have a <use> element with a URL that points to another element within the same document. In that case the href is just the URL fragment, e.g. #elementID. To accommodate this use case, the TrustedResourceURL builder is also updated to allow standalone URL fragments. PiperOrigin-RevId: 480590023
The attribute contains a URL that points to an SVG fragment to be loaded and presented inside the element. The URL can additionally contain a URL fragment representing the ID of a particular element to fetch from within that fragment. See https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#iri for details. The <use> element only supports loading same-origin resources, but data: and javascript: URLs could cause XSS (e.g. w3c/trusted-types#357) and are thus sanitized. PiperOrigin-RevId: 480590023
The attribute contains a URL that points to an SVG fragment to be loaded and presented inside the element. The URL can additionally contain a URL fragment representing the ID of a particular element to fetch from within that fragment. See https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#iri for details. The <use> element only supports loading same-origin resources, but data: and javascript: URLs could cause XSS (e.g. w3c/trusted-types#357) and are thus sanitized. PiperOrigin-RevId: 480854265
@shhnjk Do you know if this is still an issue? I remember you did some work to remove the data: URL support for svg:use, which might address this problem? |
Since data: URLs in SVGUseElement is deprecated, I think the only possible XSS from SVGUseElement is:
Then the XSS can happen. I think this situation is extremely rare, that we might not care anymore. |
Guess we can intentionally exclude this from TT coverage then? I suggest to close this. |
Agreed. Thanks all! |
We should enforce Trusted Types on
<use>
tag'shref
attribute.Found by @masatokinugawa.
https://twitter.com/kinugawamasato/status/1493576076726988802
The text was updated successfully, but these errors were encountered: