-
Notifications
You must be signed in to change notification settings - Fork 79
Bypass via insertAdjacentText #133
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
Comments
That's a good one. It's clear how to fix it for the |
I'm trying to think of an effective solution to this bypass. It seems like creating a text node (here via This attack requires that cc @otherdaniel |
It shouldn't work with nested nodes as only the direct child text content of a |
The "direct child text content" thing is a pretty good hint; I had overlooked that. Could we spec & implement it like the regular checks for 'afterbegin' and 'beforeend', and as a check against the parent for 'beforebegin' and 'afterend'? That's a tad awkward to implement (because irregular), but should otherwise cover this case, shouldn't it? |
Hrm. Which default policy should be used for 'beforebegin'/'afterend'? That suitable for the parent element, I guess? |
@otherdaniel Which 'afterbegin' and 'beforeend' checks do you have in mind? |
Hooking into pre-insert would also cover:
Does that help with the implementation? What do you mean regarding the default policy? There's only one, unless you mean for cross-document insertion (in that case, I'd apply the policy local to the parent element, script in this case). |
Actually, that should be in https://dom.spec.whatwg.org/#concept-node-insert , to also cover |
FIxing this comprehensively (e.g. guard at text node insertion to a script node) requires a slightly different approach than just hijacking the setters. We'd have to either annotate the type that was used to set the node content (e.g. that it was a Alternatively, we trigger the default policy's |
@mikesamuel: What I should have said is that 'afterbegin' and 'beforeend' should be treated as they currently are, which is: no checks. @koto: I'm very nervous about "annotate the type that was used to set the node content" & similar. That is a massive extension of the trusted types concept, both conceptually & implementation-wise. Currently, Trusted Types sits at the boundary of any string-goes-into-DOM, while that would get us into a much larger boundary that goes through pretty much all DOM operations. Hrm. So after re-reading all of the discussion here, and after discussing this with @mikewest: Initially, I had seen this as a problem of only the insertAdjacentText method. The discussion here convinces me that doesn't hold, because creating text nodes and inserting those in <script> elements has all the same problems, regardless of which DOM manipulation methods are being used. I think it's more that our String -> DOM boundary doesn't quite hold when it comes to the <script> element. So I think we'd need to treat that element differently. (koto said as much) So... the main question I have: Is this a problem of only the <script> element? Are there other elements/APIs where inserting a text node is effectively a trusted types bypass? If it's only <script>, then we can treat that element differently: Either by disallowing text node insertions when trusted types is enabled (what Mike prefers), or by treating text node insertions (when trusted types is enabled) like a text assignment and run the default policy. |
For all we know, and for addressing DOM XSS, only the |
I would lean to a default policy invocation. So you can manipulate script body in two ways:
|
Yes. Since we have elected not to spec TrustedStylesheet, we can ignore I'm not familiar with whether |
(Sorry, commenting in tab that I hadn't reloaded so missed koto's update.) |
This is addressed in Chrome via https://chromium-review.googlesource.com/c/chromium/src/+/1547746 (in progress). Adding @annevk, as this approach might actually be non-speccable. |
To clarify, we aim to prevent appending text nodes to script elements (which would also cover the insertAdjacentText bypass). Spec-wise, it seems like we might be able to throw on |
insertAdjacentText into <script> elements can be used to bypass Trusted Types checks. This change fixed that hole by adding TT checks to related Node API methods, and changing insertAdjacentText to use the public methods. See additional discussion on the root issue in w3c/trusted-types#133 Bug: 739170 Change-Id: Ie26b2aca2d60c7e14a0118c6fd957f32928afabf
insertAdjacentText into <script> elements can be used to bypass Trusted Types checks. This change fixed that hole by adding TT checks to related Node API methods, and changing insertAdjacentText to use the public methods. See additional discussion on the root issue in w3c/trusted-types#133 Bug: 739170 Change-Id: Ie26b2aca2d60c7e14a0118c6fd957f32928afabf
insertAdjacentText into <script> elements can be used to bypass Trusted Types checks. This change fixed that hole by adding TT checks to related Node API methods, and changing insertAdjacentText to use the public methods. See additional discussion on the root issue in w3c/trusted-types#133 Bug: 739170 Change-Id: Ie26b2aca2d60c7e14a0118c6fd957f32928afabf
insertAdjacentText into <script> elements can be used to bypass Trusted Types checks. This change fixed that hole by adding TT checks to related Node API methods, and changing insertAdjacentText to use the public methods. See additional discussion on the root issue in w3c/trusted-types#133 Bug: 739170 Change-Id: Ie26b2aca2d60c7e14a0118c6fd957f32928afabf Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1547746 Reviewed-by: Mason Freed <[email protected]> Commit-Queue: Daniel Vogelheim <[email protected]> Cr-Commit-Position: refs/heads/master@{#669210}
insertAdjacentText into <script> elements can be used to bypass Trusted Types checks. This change fixed that hole by adding TT checks to related Node API methods, and changing insertAdjacentText to use the public methods. See additional discussion on the root issue in w3c/trusted-types#133 Bug: 739170 Change-Id: Ie26b2aca2d60c7e14a0118c6fd957f32928afabf Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1547746 Reviewed-by: Mason Freed <[email protected]> Commit-Queue: Daniel Vogelheim <[email protected]> Cr-Commit-Position: refs/heads/master@{#669210}
insertAdjacentText into <script> elements can be used to bypass Trusted Types checks. This change fixed that hole by adding TT checks to related Node API methods, and changing insertAdjacentText to use the public methods. See additional discussion on the root issue in w3c/trusted-types#133 Bug: 739170 Change-Id: Ie26b2aca2d60c7e14a0118c6fd957f32928afabf Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1547746 Reviewed-by: Mason Freed <[email protected]> Commit-Queue: Daniel Vogelheim <[email protected]> Cr-Commit-Position: refs/heads/master@{#669210}
insertAdjacentText into <script> elements can be used to bypass Trusted Types checks. This change fixed that hole by adding TT checks to related Node API methods, and changing insertAdjacentText to use the public methods. See additional discussion on the root issue in w3c/trusted-types#133 Bug: 739170 Change-Id: Ie26b2aca2d60c7e14a0118c6fd957f32928afabf Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1547746 Reviewed-by: Mason Freed <[email protected]> Commit-Queue: Daniel Vogelheim <[email protected]> Cr-Commit-Position: refs/heads/master@{#669210}
…ns into <script> elements., a=testonly Automatic update from web-platform-tests [trusted types] Check text node insertions into <script> elements. insertAdjacentText into <script> elements can be used to bypass Trusted Types checks. This change fixed that hole by adding TT checks to related Node API methods, and changing insertAdjacentText to use the public methods. See additional discussion on the root issue in w3c/trusted-types#133 Bug: 739170 Change-Id: Ie26b2aca2d60c7e14a0118c6fd957f32928afabf Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1547746 Reviewed-by: Mason Freed <[email protected]> Commit-Queue: Daniel Vogelheim <[email protected]> Cr-Commit-Position: refs/heads/master@{#669210} -- wpt-commits: 90a794e8e93a5e22e7cb3b2f8c79d751989fa7b0 wpt-pr: 17230
…ns into <script> elements., a=testonly Automatic update from web-platform-tests [trusted types] Check text node insertions into <script> elements. insertAdjacentText into <script> elements can be used to bypass Trusted Types checks. This change fixed that hole by adding TT checks to related Node API methods, and changing insertAdjacentText to use the public methods. See additional discussion on the root issue in w3c/trusted-types#133 Bug: 739170 Change-Id: Ie26b2aca2d60c7e14a0118c6fd957f32928afabf Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1547746 Reviewed-by: Mason Freed <[email protected]> Commit-Queue: Daniel Vogelheim <[email protected]> Cr-Commit-Position: refs/heads/master@{#669210} -- wpt-commits: 90a794e8e93a5e22e7cb3b2f8c79d751989fa7b0 wpt-pr: 17230
…ns into <script> elements., a=testonly Automatic update from web-platform-tests [trusted types] Check text node insertions into <script> elements. insertAdjacentText into <script> elements can be used to bypass Trusted Types checks. This change fixed that hole by adding TT checks to related Node API methods, and changing insertAdjacentText to use the public methods. See additional discussion on the root issue in w3c/trusted-types#133 Bug: 739170 Change-Id: Ie26b2aca2d60c7e14a0118c6fd957f32928afabf Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1547746 Reviewed-by: Mason Freed <masonfreedchromium.org> Commit-Queue: Daniel Vogelheim <vogelheimchromium.org> Cr-Commit-Position: refs/heads/master{#669210} -- wpt-commits: 90a794e8e93a5e22e7cb3b2f8c79d751989fa7b0 wpt-pr: 17230 UltraBlame original commit: edd51bf2c9befb08253cc19fefb1f7fe64def9b3
…ns into <script> elements., a=testonly Automatic update from web-platform-tests [trusted types] Check text node insertions into <script> elements. insertAdjacentText into <script> elements can be used to bypass Trusted Types checks. This change fixed that hole by adding TT checks to related Node API methods, and changing insertAdjacentText to use the public methods. See additional discussion on the root issue in w3c/trusted-types#133 Bug: 739170 Change-Id: Ie26b2aca2d60c7e14a0118c6fd957f32928afabf Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1547746 Reviewed-by: Mason Freed <masonfreedchromium.org> Commit-Queue: Daniel Vogelheim <vogelheimchromium.org> Cr-Commit-Position: refs/heads/master{#669210} -- wpt-commits: 90a794e8e93a5e22e7cb3b2f8c79d751989fa7b0 wpt-pr: 17230 UltraBlame original commit: edd51bf2c9befb08253cc19fefb1f7fe64def9b3
…ns into <script> elements., a=testonly Automatic update from web-platform-tests [trusted types] Check text node insertions into <script> elements. insertAdjacentText into <script> elements can be used to bypass Trusted Types checks. This change fixed that hole by adding TT checks to related Node API methods, and changing insertAdjacentText to use the public methods. See additional discussion on the root issue in w3c/trusted-types#133 Bug: 739170 Change-Id: Ie26b2aca2d60c7e14a0118c6fd957f32928afabf Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1547746 Reviewed-by: Mason Freed <masonfreedchromium.org> Commit-Queue: Daniel Vogelheim <vogelheimchromium.org> Cr-Commit-Position: refs/heads/master{#669210} -- wpt-commits: 90a794e8e93a5e22e7cb3b2f8c79d751989fa7b0 wpt-pr: 17230 UltraBlame original commit: edd51bf2c9befb08253cc19fefb1f7fe64def9b3
This issue is not fixed properly in the polyfill: This test fails (and alert is triggered): fit('insertAdjacentText not working properly', () => {
const enforcer = new TrustedTypesEnforcer(ENFORCING_CONFIG);
enforcer.install();
const s = document.createElement('script');
const p = document.createElement('p');
s.appendChild(p);
expect(() => {
s.insertAdjacentText(
'afterBegin',
'alert("script.insertAdjacentText");'
);
}).toThrow();
document.body.appendChild(s);
enforcer.uninstall();
document.body.innerHTML = '';
}); Note, you have already a similar test, which asserts that calling |
insertAdjacentHTML
is covered in TrustedTypes as an unsafe sink and treated as HTML context. In the<script>
taginsertAdjacentText
might also be dangerous. It is worth noting that it's dangerous not only on a<script>
tag itself but also if it contains any children (but probably nobody should do that anyway?).Consider the following example:
The text was updated successfully, but these errors were encountered: