mganss / HtmlSanitizer

Cleans HTML to avoid XSS attacks
MIT License
1.55k stars 200 forks source link

<body onload=alert(1)> will not trigger RemovingAttribute event #410

Closed hgy225 closed 1 year ago

hgy225 commented 1 year ago

when run below code new HtmlSanitizer().Sanitize("<body onload=alert(1)>") Sanitizer will not trigger RemovingAttribute event but when run ` new HtmlSanitizer().Sanitize("

")` Sanitizer will trigger RemovingAttribute event is this a bug or by design?

mganss commented 1 year ago

The Sanitize() method treats the supplied string as a fragment, i.e. it assumes it to be inside the body already. If you want to sanitize an HTML document containing head and body, use the SanitizeDocument() method instead.