News for hackers. Stuff that matters.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by cogman10 on Tuesday February 24, 2026 @09:32AM (#47137629)
> Who would ever want this?

The main case I can think of is wanting some forum functionality. Perhaps you want to allow your users to be able to write in markdown. This would provide an extra layer of protection as you could take the HTML generated from the markdown and further lock it down to only an allowed set of elements like `h1`. Just in case someone tried some of the markdown escape hatches that you didn't expect.

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by Aachen on Tuesday February 24, 2026 @09:41AM (#47137753)
> This would provide an extra layer of protection

I think this might be the answer. There's no point to it by itself (either you separate data and code or you don't and let the user do anything to your page), but if you're already using a sanitiser and you can't use `textContent` because (such as with Markdown) there'll be HTML tags in the output, then this could be extra hardening. Thanks!

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by iLoveOncall on Tuesday February 24, 2026 @01:43PM (#47140893)
You'd never want to store the processed HTML anyway, this is website building 101.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by efilife on Tuesday February 24, 2026 @03:59PM (#47142948)
I store both, to serve processed HTML faster, and to be able to rebuild it just in case. Is this ok?
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by joquarky on Tuesday February 24, 2026 @08:53PM (#47146311)
I wouldn't trust myself to always remember to sanitize it, and in a company with more than one person, it becomes impossible to ensure it is properly handled.