Sanitize.js icon indicating copy to clipboard operation
Sanitize.js copied to clipboard

Sanitize isn't doing anything?

Open flound1129 opened this issue 10 years ago • 4 comments

What am I doing wrong here?

http://jsfiddle.net/fe9pd8uy/

flound1129 avatar Aug 18 '15 22:08 flound1129

It does work it just returns a document fragment instead of 'foo' like as expected in the docs. Perhaps you want to replace the element with the filtered element like this. http://jsfiddle.net/fe9pd8uy/3/

johnsonjo4531 avatar Aug 28 '15 21:08 johnsonjo4531

Shouldn't the default code strip all tags and just leave 'foo'? Why is the img tag still there?

flound1129 avatar Aug 29 '15 01:08 flound1129

What it does when you call sanitize is return a sanitized node. It does not modify the node directly that you select. You need to replace the un-sanitized node with the sanitized one. I tried to explain it a little more in this fiddle what I did in my last fiddle. http://jsfiddle.net/fe9pd8uy/5/

I get the feeling that if you're trying to prevent XSS you probably should never have unsafe dom elements on your page so you would do it more like this. This might be a general use case if that's your case. http://jsfiddle.net/fe9pd8uy/6/.

Sorry for the late reply.

johnsonjo4531 avatar Sep 28 '15 05:09 johnsonjo4531

OK thank you

flound1129 avatar Oct 09 '15 00:10 flound1129