DOMPurify icon indicating copy to clipboard operation
DOMPurify copied to clipboard

Not able to sanitize dirty string

Open ag0059985 opened this issue 4 years ago • 2 comments

This issue proposes a [bug, feature] which...

Background & Context

I am trying to use dompurify.sanitize function on below string, and this string is binding of html.

"p\ul onbeforecopy="alert(2)" contenteditabletest\/ul\br / \video onmouseover=alert(document.cookie) tabindex=1 id=x\\/video\\input autofocus\br /"

Bug

so when trying to use DOMPurify.sanitize function on this string, in return i am getting the same string, and in result document.cookie are getting shown on page in alert dialog box

Input

"p\ul onbeforecopy="alert(2)" contenteditabletest/ul\br / \video onmouseover=alert(document.cookie) tabindex=1 id=x\/video\input autofocus\br /"

Given output

"p\ul onbeforecopy="alert(2)" contenteditabletest/ul\br / \video onmouseover=alert(document.cookie) tabindex=1 id=x\/video\input autofocus\br /"

Expected output

"p\ul tabindex=1 id=x\/video\input autofocus\br /"### Feature

Please let me know if I am doing something wrong, and this is an expected result.

Thanks

ag0059985 avatar Aug 25 '22 11:08 ag0059985

Heya, we only sanitize HTML, not anything that resembles HTML or might serve as HTML binding. So, this is the expected result.

Feed us actual HTML and it will work as intended, sanitization will take place :)

cure53 avatar Aug 25 '22 12:08 cure53

Not sure if this is the right place but if that string is not sanitised, does it represent a threat? And what should I use to prevent this?

kamiranoff avatar Sep 28 '23 22:09 kamiranoff