Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection...
by Cthulhu_ on Tuesday February 24, 2026 @10:37AM
(#47138499)
Ideally you should be able to set a global property somewhere (as a web developer) that disallows outdated APIs like `innerHTML`, but with the Big Caveat that your website will not work on browsers older than X. But maybe there's web standards for that already, backup content if a browser is considered outdated.
[ Parent
| on HN ]
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection...
by staticassertion on Tuesday February 24, 2026 @10:52AM
(#47138646)
Doesn't using TrustedTypes basically do that? I'm not really web-y, someone please correct me if I'm off.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection...
by madeofpalk on Tuesday February 24, 2026 @12:03PM
(#47139514)
Yup, this is basically what TrustedTypes is for!
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection...
by afavour on Tuesday February 24, 2026 @10:44AM
(#47138572)
I like the idea of that. But I imagine linting rules are a much more immediate answer in a lot of projects.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection...
by cxr on Tuesday February 24, 2026 @03:56PM
(#47142897)
It's not an "outdated API". It's still good for what it was always meant for: parsing trusted, application-generated markup and atomically inserting it into the content tree as a replacement for a given element's existing children.
> set a global property somewhere (as a web developer) that disallows[…] `innerHTML`
Object.defineProperty(Element.prototype, "innerHTML", {
set: (() => { throw Error("No!") })
});
(Not that you should actually do this—anyone who has to resort to it in their codebase has deeper problems.)