-
Notifications
You must be signed in to change notification settings - Fork 31
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
Sanitizer vs Trusted Types #20
Comments
DOMPurify adds an option for Trusted Types as a return type. An alternative might be a change to TT, so that a TT policy can accept a sanitizer config in lieu of a callback function. That would preserve TT's review-ability, as it maintains the property that only TT policies can generate trusted type instances. |
I think sanitizer should have option to return TrustedHTML instead of string. To me, Trusted Types is a way to enforce proper sanitization on dangerous sinks. Creating Trusted Type policy with selecting sanitizer API in createHTML does not make sense to me, if browser already knows that sanitized output is known to be good. CC: @koto |
Hmm. If Sanitizer(s) can create TrustedHTML, and if the user can create different sanitizers with potentially silly options (e.g. Or would this power be automatically conferred to all sanitizer instances? (Presumably with the understanding that sanitizer configs can only tighten the defaults, but not loosen them?) |
So, let's say safe option we believe is This would really benefit folks who would like to use Trusted Types. Because currently, readability of JS code is a challenge when converting existing code to Trusted Types. And usually this would mean to creating Trusted Type policy with static HTML. Maybe, how about we create |
Reading at the syntax, maybe we would only expose |
This also makes sense, but then I don't like the naming of |
I think a main contribution of the spec should be to define a safe subset of HTML. |
Interesting. I had assumed that users could configure whatever they want, but actually don't have a good reason for why. If we do think we can do always-safe sanitizer configs, then we could maybe use a CSP keyword in the TT directive (e.g. |
Small nit: There is no always-safe sanitizer config. Due to script gadgets (which are common, as we've found), any DOM tree can potentially lead to JS execution. If the intention is to enable easy (e.g. configured only declaratively) sanitization for the long tail of websites, said websites remain practically vulnerable to this "second order" XSS. That is not a direct cause for concern for the Sanitizer API, but an argument against overpromising. |
I agree with @koto here. There is no always-safe sanitizer configs for script gadgets, and no customization to sanitizer is a deal breaker. When it comes to integration with Trusted Types, we would want to block configuration that does not match with Trusted Types (thus require TT policy creation). That is, Sanitizer API can return TrustedHTML as long as config is known to prevent XSS with vanilla JS. For example, we would allow assigning arbitrary value to This makes sense because DOM API would be able to do the same thing without causing a TT violation, and TT would only get angry when specific library tries to evaluate |
The specification cannot account for arbitrary scripts on the page that turn an attribute (id, data-.., etc.) into HTML / script though.. |
I think you're both saying the same thing. @mozfreddyb, are you referring to something else than #20 (comment)? TT set a specific boundary, and the bug is to make sure the sanitizer is not a bypass vector. Which it's not, unless a sanitizer can produce nodes from strings that would normally use the "native" DOM XSS sinks. If the sanitizer output has ids, names and other gadget-inducing attributes, it could still be |
I've tried to take the earlier work from Jun, and to expand it a bit based on the current state of the spec, resulting in PR #49. I'd appreciate in @shhnjk @koto and @iVanlIsh could have a look. Overview:
|
New Trusted Types PR in #55. I don't think we reached consensus on PR #49, so I've tried to take what I've learned and made have now made a new attempt. Please liberally comment - here or there - on whether think it's agreeable. Main differences between #49 and #55:
|
New New Trusted Types proposal. No PR yet. Doc here: https://github.com/otherdaniel/purification/blob/trustedtypes-3/trustedtypes.md (I'll gladly turn it into a proper PR, it that helps.) I think we didn't really reach consensus on PR #55 either, so this time it's more of an Explainer / Position Paper about how to use Santizer and Trusted Types together. It's less about what to specify, and more about how to use these two things to achieve the common goal, XSS-free apps. I've been careful not to mix explainer stuff with new proposals. It doesn't assume any change to the current spec. It does mention several options at the bottom, though. My intent is to maybe leave it at that for now. We could then wait for external feedback and base our future path on what we hear from developers. Does this make any sense? |
Can we agree somewhere in the middle round?
I think we aren't reaching consensus on Sanitizer API's defaults VS built-ins, but I don't think that matter much to the problem of static HTML assignment to dangerous sinks. As long as Sanitizer API returns natively XSS-safe output, than we should provide a way to not cause a TT violation when assigning unsafe input to dangerous sinks through Sanitizer API (either with |
My intent here now is to concentrate on what everyone agrees on - which isn't very much - and to punt the rest to later. I understand that we'll have to do a second round on this. I also understand this makes almost no-one happy - certainly not me - but I hope we can at least make some progress that way. IMHO, if we can't agree on API structure, then the real solution is to push this towards a public trial, and then figure out what developers out there are actually missing. We should avoid constraining the future path until then.
|
IIUC, string argument to And default TT policy shouldn’t be used in JS libraries/frameworks, as default TT policy is meant to be used by Web Apps. |
As a rando web dev, my two cents is that converting from a string to a document fragment to a string to another document fragment (which is my understanding of what |
If an output from Sanitizer API can cause an mXSS, then that's a problem of Sanitizer API itself. If we promised to provide natively XSS-free sanitizer, then producing an mXSS output is a deal breaker. mXSS is caused by a mutation of the browser itself. So Sanitizer API is in the best position to solve that issue. If we can't solve that, then I'm opposed of even providing |
Here is my official feedback with my developer's hat on: |
Coming back to this, I think my problem of allowing developers to assign static HTML can be solved with HTML Modules. However, I think there is a major problem of integrating Sanitizer API with Trusted Types for So if we don't think about integration, usage of Sanitizer API under Trusted Types enforcement will probably result in more usage of |
Thanks for bringing this up again. In the mean time, #42 happened, and I think the APIs proposed there change the situation a good bit, hopefully for the better:
I think the core issue for Trusted Types integration - whether Sanitizer is considered a TT boundary or not - is still open. As I read it, the majority opinion is that - if Sanitizer is XSS-safe by default - then it shouldn't do TT checks. I'd be okay with that. Please take a minute and hop over to #42, whether this makes your life easier (or not). I'd like to wrap that one up soon-ish, so feedback would be much appreciated. |
For existing TT, it sounds okay. However, if TT implements something like So there needs to be a way to control Sanitizer globally in the document, either in the Sanitizer API or in the Trusted Types. But I think it should be done in the Trusted Types (I personally like this example by @koto). The question is, if Trusted Types has new restrictions (e.g. blocking text assignment to style element without If we agree on TT controlling Sanitizer API globally in the future, then it's important to tell developers that Sanitizer API should be used only for sanitizing untrusted input. If they use it for static html assignment, the output might change in the future based on Trusted Types config (especially in the third-party frameworks/libraries). |
Fwiw, I know this will be hard, but I'd strive for the sanitizer to always return an xss-safe value, which should make this all a bit simpler. |
Sure, no doubt about that 😊 But what I'm saying here is, what happens if Trusted Types will create a new mode, where it will do type enforcement for CSS. Sanitizer API doesn't care about CSS injection, so it'll allow style tags. But Trusted Types would want to block that. In that situation, I think that the Sanitizer API's output should comply with Trusted Types, regardless of what config was passed (because the config of Sanitizer API might come from third-party library, but Trusted Types enforcement always comes from the Website owner). |
Closing. (Please reopen if someone strongly disagrees.) With the introduction of a non-overridable "baseline" into the Sanitizer, the Sanitizer maintains a guarantee to never contain script-ish output. A script-ish sink in the Sanitizer output should be considered a blocking bug in the Sanitizer itself, rather than "only" a Trusted Types issue. With that, I think we don't have to treat the Sanitizer as a TT sink. Personally, I kinda like the result: We'll have the Sanitizer as an easy-to-use XSS-safe means to create DOM trees, and TT as a means to prevent other, unsafe means from doing the same. That's a good combo. I think the concern that future evolutions of either Sanitizer or TT might evolve in different directions still stands. But I don't see a way to handle that preemptively. |
The resulting APIs should be integratable with Trusted Types.
The text was updated successfully, but these errors were encountered: