Conversation
|
Two things for the top comment, I don't think you do fold set and filter html anymore? Also this also doesn't touch execCommand with the insertHTML command. (This is probably the right move because that isnt specced correctly to start with. But worth calling out probably). |
Thanks, OP updated. |
|
Did we decide it was okay to not enforce the sanitizing if the document was XML? |
That's what I understood but @mozfreddyb, @evilpie or @otherdaniel would know more. Sanitization is not specified for the XML parser. |
What I remember is that we specified Sanitizer API only for methods that would inherently only support HTML syntax. This is probably best articulated in the hopelessly outdated explainer Nearly all interesting bits are specified in terms of DOM & DOM operations, so I'd expect this to be easy to adapt to XML. But IMHO, application to XML-parser parse trees requires a second look, since it invalidates one of the assumptions we had when specifying any of this. A silly example, but the only one I can think of: CDataSection in https://wicg.github.io/sanitizer-api/#sanitize-core step 1.1. That shouldn't be difficult to fix; but at least for now Sanitizer would assert-fail on (some) XML parse trees. In our implementation, there's a runtime assert there. |
|
I guess my main concern is people defining a trusted types policy with this new function thinking it protects them and then it doesn't because they're in XHTML or something? Assuming I'm reading this right you'd end up with a default policy explicitly setup to remove unsafe and then it actually no-ops when it's called by a legacy sync in XML. |
You mean sink? Yea it's limited in that way. But |
I think that the specific guidance to developers to be to check the type of document when they create the default policy, use createHTML with the appropriate userland sanitizer if either this is an XML document or TrustedParserOptions is not supported, and createParserOptions otherwise |
|
Non-authoratative LGTM. I'm still slightly unsure about the XML case mentioned above but if the consensus is that it's fine then I buy that. |
… algorithm steps signature
In the places where TrustedTypes'
createHTMLis called,we now also check for
createParserOptionsand call that if it's available, by calling "get trusted type compliant input" instead of "get trusted type compliant string".This now allows us to use the sanitizer in legacy markup insertion methods (
innerHTML,outerHTML,insertAdjacentHTML,createContextualFragment()), and to also disallow running scripts increateContextualFragment(). This also allows the policy to restrict modern calls likesetHTMLUnsafe.The exceptions to this are
srcdoc,document.write(),DOMParser.parseFromString(), and theinsertHTMLexecCommand. We can resolve separately as to whether these should also be sanitized withcreateParserOptions.Since all markup insertion methods can now include a sanitizer, most of the steps from "set and filter HTML" are folded into the "fragment parsing algorithm steps", with handling of a null sanitizer when appropriate.
This PR also removes the
= {}defaults fromSetHTMLUnsafeOptions.sanitizerandParseHTMLUnsafeOptions.sanitizerso that the default policy can distinguish between an omitted sanitizer member and an explicit configuration.A default policy is only allowed to provide a sanitizer for HTML documents. In XML documents the
createParserOptionsshortcut does not apply, socreateHTML(or aTrustedHTML) is still required, exactly as today.Additionally, "configure a sanitizer" now clones its input configuration before canonicalizing, fixing an issue where the
built-in safe default configurationsingleton was mutated in place on first use.Note that setting a sanitizer policy by trusted types has a known limitation, as the sanitizer configuration cannot handle JavaScript navigation URLs. See #12686
Together with w3c/trusted-types#606
Sanitizer)(See WHATWG Working Mode: Changes for more details.)