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

Sanitizing the template tags are not supported #185

Closed
smasam opened this issue Nov 2, 2016 · 1 comment
Closed

Sanitizing the template tags are not supported #185

smasam opened this issue Nov 2, 2016 · 1 comment

Comments

@smasam
Copy link

smasam commented Nov 2, 2016

I am using HTML5 templates for my UI, before I read the template and cache it, when ever required, I clone the template content and then render, so now using DOMPurify I would like to sanitize the template, but when I try to do this, DOMPurify does not return any content, looks like DOMPurify is using DOMParser to parse the html string, which eventually adds the template to the head, and for sanitizing the content( text) the DOMPurifier only considers body tag, which cannot any template and nothing is returned, but if we use WHOLE_DOCUMENT, we can get the template, but this should be supported even with out WHOLE_DOCUMENT flag, can you please add the support to parse the standalone template.

@cure53
Copy link
Owner

cure53 commented Nov 2, 2016

Heya, I reviewed the issue - and it's the same problem with for example style elements and other nodes that the browser automatically places in the header.

If DOMPurify starts working around that, we put ourselves into a very risky position. Likely, different browsers will do different things and we have to build code around that - which we don't want.

The way you already proposed looks best to me:

// Specify dirty template
var dirty = '<template><script><\/script><b></b></template>';

// Clean template and return DOM fragment
var clean = DOMPurify.sanitize(dirty, {WHOLE_DOCUMENT: true, RETURN_DOM_FRAGMENT: true});

console.log(clean.querySelector('template'));
console.log(clean.querySelector('template').innerHTML);

So, this is a wontfix from our side - but I hope the proposed solution helps.

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