Skip to content
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

Is "code updating a script before it finishes parsing" within the threat model of Trusted Types? #532

Closed
lukewarlow opened this issue Jul 2, 2024 · 4 comments

Comments

@lukewarlow
Copy link
Member

Based on lots of the discussions around the exact mechanics of TT enforcement within scripts, a question came up. Is code that ends up updating the contents of a script before it finishes parsing within the threat model of the Trusted Types API?

My understanding of the threat model is that it's based on trusted code manipulating untrusted strings into various XSS sinks.

That case doesn't seem to apply to this situation? It's reliant on at what would seem to be weird at best, or actively malcious at worst code?

cc @otherdaniel @koto @annevk and @mbrodesser-Igalia what are your thoughts on this?

@otherdaniel
Copy link
Member

otherdaniel commented Jul 2, 2024

My understanding of the threat model is, (dynamically) constructed strings that get executed as javascript. Strings that are already on the loaded page -- such as <script> -- are not dynamically constructed by the page and thus shouldn't be TT-checked.

My understanding of the script-loading situation is that the <script> is surely on the page; if you try hard enough, you can stick in additional content into a <script> during page load; and this additional content would be executed. So the script that was executed was indeed dynamically constructed and quite different from the one on the original page. That seems to solidly cross the border that TT was meant to guard.

I think the only thing that makes this situation special is that it's difficult to exploit due to the required timing. But I don't think that creates a satisfactory security boundary.

@lukewarlow
Copy link
Member Author

if you try hard enough.

The "you" here is the site author who we assume is trustworthy enough to not deliberately evade TT protections? Having to try hard to cause this to happen sounds like it would fall into "malicious author" to me?

@otherdaniel
Copy link
Member

if you try hard enough.

The "you" here is the site author who we assume is trustworthy enough to not deliberately evade TT protections? Having to try hard to cause this to happen sounds like it would fall into "malicious author" to me?

I'm not sure this would require a "malicious author". It probably does require that user-controlled data is processed during page build-up, and it requires a slow script load. Both are imaginable in real-world applications.

The condition was originally found by a fuzzer. (https://g-issues.chromium.org/issues/40111196) IMHO the presence of a fuzz-exploitable loophole points more towards, could happen to an inattentive developer, rather than malicious.

@lukewarlow
Copy link
Member Author

Okay thanks for answering! Looks like the answer is yes it is, so we do need to find a way to protect it that works in all browsers and can be specced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants