-
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
proposed api: innerHTML setter that takes template strings #102
Comments
I'm quoting @shhnjk's comment as this the most cohesive summary of what @koto suggested upthread. I hope you don't mind. The idea is that we have an HTML-setter that is used as a tagged template string and can therefore distinguish literals from other strings and sanitize accordingly. I think this needs to wait until v2, but happy to hear otherwise. |
I'd suggest |
Yes, that sounds good. I agree that has little to do with the sanitizer itself. |
Wouldn't this require some degree of language support? I thought several related proposals were made to TC39, but none of them made it (yet?). |
The proposals were for a user-callable function. I think the existing machinery in ES allows us to implement this check already in a platform mechanism (not sure how elegant that is though, and whether it needs adjusting WebIDL). Effectively one checks if the template object (first argument to the function) is already present in the elem.setRawHTML`abc` Note that "bypasses" are possible, like below, but still at some point the whole value was a literal in the code. const literal = (foo=>foo)`bar`;
elem.setRawHTML(literal); |
Note that the correct form is |
Thanks @domenic, I didn't realize that fag functions cannot have side effects (I know many in our codebases that do, though)! Under this restriction, indeed |
Perhaps if the tag function returned a Then |
This sounds good, but can we also add this method to other Trusted Types? That is, |
We ended up solving this in a different way with safe and unsafe methods. See also #196. |
(...)
To give more high-level description, Web Platform currently doesn't have a way to say developers are assigning static string or dynamic string.
That is,
AND
Are both string assignment (even though one is static and one is dynamic). What @koto suggested is to give a primitive to developers, where the platform can understand the notion of static string assignment. This primitive is important in the platform, because if we know something is static, it is safe to append without sanitization.
BTW,
elem.setHTML.withLiterals`this_is_not_injected_for_sure`
sounds better (remember, this is the thread to decide namings 😋)Originally posted by @shhnjk in #100 (comment)
The text was updated successfully, but these errors were encountered: