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

Should calling saneStringFrom be caught by Trusted Types? #5

Closed
shhnjk opened this issue Jul 30, 2020 · 2 comments
Closed

Should calling saneStringFrom be caught by Trusted Types? #5

shhnjk opened this issue Jul 30, 2020 · 2 comments

Comments

@shhnjk
Copy link

shhnjk commented Jul 30, 2020

Currently, triggering any HTML parser using DOM API makes Trusted Types angry, and Trusted Types requires sites to parse TrustedHTML.

Will saneStringFrom have same thing? Or will it never cause TT violation?

CC: @koto

@otherdaniel
Copy link
Owner

Thanks for the feedback.

I think of the HTML parser as an implementation detail. I think a string -> string sanitation should not trigger TT.
string -> DOMFragment should however be considered a TT sink.

Generally, the TT/sanitizer interaction is a bit unclear to me, but my thinking is that maybe we should keep the sanitizer oblivious to Trusted Types, and instead extend Trusted Types so that you can directly put a sanitizer config into a TT policy.

E.g., something like
let policy = trustedTypes.createPolicy("bla", { createHTML: { 'allow': ['b', 'em'], 'block': ['blabla'] } });
would do much the same thing as:

let tmp = new Sanitizer({ 'allow': ['b', 'em'], 'block': ['blabla'] });
let policy = trustedTypes.createPolicy("bla", { createHTML: s => tmp.saneStringFrom(s) });

That way, TT policy creation and policy instances would remain the central controlling element for TT, but it'd still be very easy to combine TT with sanitizers.

Related discussion here: WICG/sanitizer-api#20

@koto
Copy link

koto commented Jul 31, 2020

Correct. The exact API shape tbd. For example, we might allow the sanitizer instance be passed in the policy options:

trustedTypes.createPolicy('default', { htmlSanitizer: new Sanitizer(params) });

@shhnjk shhnjk closed this as completed Aug 3, 2020
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

3 participants