Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection...
by snowhale on Tuesday February 24, 2026 @09:04AM
(#47137295)
the browser-native Sanitizer API has one advantage the library approaches don't: it uses the same HTML parser the browser uses to render. libraries like DOMPurify parse in a separate context then re-serialize, and historically that round-trip is where most bypasses came from. when the sanitizer and the renderer share the same parser, mutation XSS attacks have nowhere to hide.
[ Parent
| on HN ]
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection...
by pornel on Tuesday February 24, 2026 @09:52AM
(#47137886)
BTW, HTML allows inline SVG with an XML-flavored syntax that interprets <script/> and <title> differently. It's a goldmine for sanitizer escapes. There are completely bonkers syntax switching and error recovery rules that interact with parsing modes (there's even an edge case where a particular attribute value switches between HTML and XML-ish parsing rules).
Don't even try to allow inline <svg> from untrusted sources! (and then you still must sanitise any svg files you host)
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection...
by kccqzy on Tuesday February 24, 2026 @10:55AM
(#47138677)
If you just serve SVGs through <img> tag it’ll be much safer. I never understood the appeal of inline <svg> anyways.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection...
by rwj on Tuesday February 24, 2026 @11:58AM
(#47139423)
Inline reduces round trips.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection...
by toast0 on Tuesday February 24, 2026 @12:11PM
(#47139618)
You can use img with a data url?
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection...
by lenkite on Tuesday February 24, 2026 @12:19PM
(#47139753)
Inline SVG is stylable with CSS styles in the same HTML page.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection...
by runarberg on Tuesday February 24, 2026 @02:01PM
(#47141124)
Also animatible with the same context (Animation API, etc.) as the parent page, so different SVGs can influence each other’s animations.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection...
by cxr on Tuesday February 24, 2026 @03:46PM
(#47142740)
It may be using some of the same deserialization machinery, but "parsing" is a broad term that includes things that the sanitizer is doing and that the browser's ordinary content-processing → rendering path does not.
Even with this being a native API, there are still two parsers that need to be maintained. What a native API achieves is to shift the onus for maintaining synchronicity onto the browser makers. That's not nothing, but it's also not the sort of free lunch that some people naively believe it is.