Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection...
by itishappy on Tuesday February 24, 2026 @10:02AM
(#47138018)
> If the default configuration of setHTML( ) is too strict (or not strict enough) for a given use case, developers can provide a custom configuration that defines which HTML elements and attributes should be kept or removed.
[ Parent
| on HN ]
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection...
by Aachen on Tuesday February 24, 2026 @10:07AM
(#47138095)
Injecting markup into someone else's website isn't what I'd call too strict a default configuration
If you mean to convey that it's possible to configure it to filter properly, let me introduce you to `textContent` which is older than Firefox (I'm struggling to find a date it's so old)
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection...
by itishappy on Tuesday February 24, 2026 @10:11AM
(#47138152)
That's the whole point of the setHTML.
How would I set a header level using textContent?
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection...
by Aachen on Tuesday February 24, 2026 @10:20AM
(#47138276)
The traditional way: separating data and code
document.createElement("h1").textContent = `Hello, ${username}!`
If you allow <h1> in the setHTML configuration or use the default, users with the tag in their username also always get it rendered as markup
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection...
by itishappy on Tuesday February 24, 2026 @10:43AM
(#47138559)
It sounds like you're arguing against a specific usecase, rather than the technology itself. If you don't want arbitrary markup in usernames, setHTML would absolutely be the wrong choice, but that's not really a good argument against setHTML.