News for hackers. Stuff that matters.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by entuno on Tuesday February 24, 2026 @08:29AM (#47136906)
This kind of thing always makes me nervous, because you end with a mix of methods where you can (supposedly) pass arbitrary user input to them and they'll safely handle it, and methods where you can't do that without introducing vulnerabilities - but it's not at all clear which is which from the names. Ideally you design that in from the state, so any dangerous functions are very clearly dangerous from the name. But you can't easily do that down the line.

I'm also rather sceptical of things that "sanitise" HTML, both because there's a long history of them having holes, and because it's not immediately clear what that means, and what exactly is considered "safe".

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by jncraton on Tuesday February 24, 2026 @09:03AM (#47137284)
You are right that the concept of "safe" is nebulous, but the goal here is specifically to be XSS-safe [1]. Elements or properties that could allow scripts to execute are removed. This functionality lives in the user agent and prevents adding unsafe elements to the DOM itself, so it should be easier to get correct than a string-to-string sanitizer. The logic of "is the element currently being added to the DOM a <script>" is fundamentally easier to get right than "does this HTML string include a script tag".

[1] https://developer.mozilla.org/en-US/docs/Web/API/Element/set...

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by entuno on Tuesday February 24, 2026 @12:12PM (#47139636)
It's certainly an improvement over people trying to homebrew their own sanitisers. But that distinction of being XSS-safe is a potentially subtle one, and could end up being dangerous if people don't carefully consider whether XSS-safe is good enough when they're handling arbitrary users input like that.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by intrasight on Tuesday February 24, 2026 @12:21PM (#47139775)
Also has made me nervous for years that there's been no schema against which one can validate HTML. "You want to validate? Paste your URL into the online validation tool."
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by Dylan16807 on Tuesday February 24, 2026 @04:22PM (#47143252)
This help? https://github.com/validator/validator

But for html snippets you can pretty much just check that tags follow a couple simple rules between <> and that they're closed or not closed correctly.

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by intrasight on Tuesday February 24, 2026 @04:50PM (#47143704)
That app does look helpful!
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.
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.)
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.
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.

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by voxic11 on Tuesday February 24, 2026 @08:43AM (#47137075)
The idea is you wouldn't mix innerHTML and setHTML, you would eliminate all usage of innerHTML and use the new setHTMLUnsafe if you needed the old functionality.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by extraduder_ire on Tuesday February 24, 2026 @09:51AM (#47137880)
I looked up setHTMLUnsafe on MDN, and it looks like its been in every notable browser since last year.

Good idea to ship that one first, when it's easier to implement and is going to be the unsafe fallback going forward.

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by onion2k on Tuesday February 24, 2026 @11:38AM (#47139183)
I looked up setHTMLUnsafe on MDN, and it looks like its been in every notable browser since last year.

Oddly though, the Sanitizer API that it's built on doesn't appear to be in Safari. https://developer.mozilla.org/en-US/docs/Web/API/Sanitizer

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by croes on Tuesday February 24, 2026 @09:22AM (#47137504)
If I need the old functionality why not stick to innerHTML?
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by orf on Tuesday February 24, 2026 @09:39AM (#47137725)
because the "unsafe" suffix conveys information to the reader, whereas `innherHTML` does not?
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by goatlover on Tuesday February 24, 2026 @10:39AM (#47138512)
Any potential reader should be familiar with innerHTML.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by kennywinker on Tuesday February 24, 2026 @11:11AM (#47138867)
Right. Like how any potential reader is familiar with the risks of sql injection which is why nothing has ever been hacked that way.

Or how any potential driver is familiar with seat belts which is why everybody wears them and nobody’s been thrown from a car since they were invented.

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by orf on Tuesday February 24, 2026 @11:34AM (#47139144)
yes, and bugs shouldn't exist because everyone should be familiar with everything.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by croes on Tuesday February 24, 2026 @12:43PM (#47140075)
But if some are marked unsafe and others are not it gives a false sense of security if something is not marked unsafe.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by orf on Tuesday February 24, 2026 @12:45PM (#47140097)
So we shouldn’t mark anything as unsafe then? And give no indication whatsoever?

The issue isn’t that the word “safe” doesn’t appear in safe variants, it’s that “unsafe” makes your intentions clear: “I know this is unsafe, but it’s fine because of X and Y”.

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by croes on Tuesday February 24, 2026 @01:23PM (#47140644)
Maybe we should add the word safe and consider everything else as unsafe
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by orf on Tuesday February 24, 2026 @02:07PM (#47141229)
Like life, things should default to being safe. Unsafe, unexpected behaviours should be exception and thus require an exceptional name.

Legacy and backwards compatibility hampers this, but going forward…

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by tbrownaw on Tuesday February 24, 2026 @09:48AM (#47137834)
Because then your linter won't be able to tell you when you're done migrating the calls that can be migrated.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by philipwhiuk on Tuesday February 24, 2026 @11:25AM (#47139026)
Because sooner or later it'll be removed.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by croes on Tuesday February 24, 2026 @12:44PM (#47140079)
And break millions of sites?
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by goatlover on Tuesday February 24, 2026 @12:54PM (#47140224)
No because the web has to remain backwards compatible with older sites. This has always been the case.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by reddalo on Tuesday February 24, 2026 @09:41AM (#47137752)
You can't rename an existing method. It would break compatibility with existing websites.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by post-it on Tuesday February 24, 2026 @09:01AM (#47137267)
> you would eliminate all usage of innerHTML

The mythical refactor where all deprecated code is replaced with modern code. I'm not sure it has ever happened.

I don't have an alternative of course, adding new methods while keeping the old ones is the only way to edit an append-only standard like the web.

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by thenewnewguy on Tuesday February 24, 2026 @09:19AM (#47137465)
If you want to adopt this in your project, you can add a linter that explicitly bans innerHTML (and then go fix the issues it finds). Obviously Mozilla cannot magically fix the code of every website on the web but the tools exist for _your_ website.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by Vinnl on Tuesday February 24, 2026 @09:18AM (#47137463)
I kinda like the way JS evolved into a modern language, where essentially ~everyone uses a linter that e.g. prevents the use of `var`. Sure, it's technically still in the language, but it's almost never used anymore.

(Assuming transpilers have stopped outputting it, which I'm not confident about.)

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by delaminator on Tuesday February 24, 2026 @09:36AM (#47137690)
for some values of "everyone" and "never".
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by thunderfork on Tuesday February 24, 2026 @09:33AM (#47137651)
Depending on the transpiler and mode of operation, `var` is sometimes emitted.

For example, esbuild will emit var when targeting ESM, for performance and minification reasons. Because ESM has its own inherent scope barrier, this is fine, but it won't apply the same optimizations when targeting (e.g.) IIFE, because it's not fine in that context.

https://github.com/evanw/esbuild/issues/1301

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by yawaramin on Tuesday February 24, 2026 @01:37PM (#47140815)
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by Vinnl on Tuesday February 24, 2026 @01:56PM (#47141063)
Ah yeah, I remember that. General point still stands: in terms of the lived experience of developers, `var` is essentially deprecated.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by plorkyeran on Tuesday February 24, 2026 @03:11PM (#47142238)
I touch JS that uses var heavily on a daily basis and I would be incredibly surprised to find out that I am alone in that.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by Vinnl on Wednesday February 25, 2026 @04:55AM (#47149532)
That is indeed why I added qualifiers to "everyone" and "never".
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by bulbar on Tuesday February 24, 2026 @09:36AM (#47137698)
It for sure happens for drop in replacements.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by littlestymaar on Tuesday February 24, 2026 @10:38AM (#47138504)
Nobody's talking about old code here.

Having an alternative to innerHTML means you can ban it from new code through linting.

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by noduerme on Tuesday February 24, 2026 @09:08AM (#47137334)
Finally, a good use case for AI.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by Aachen on Tuesday February 24, 2026 @09:33AM (#47137649)
Yeah, using a kilowatt GPU for string replacement is going to be the killer feature. I probably shouldn't even be joking, people are using it like this already
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by charcircuit on Tuesday February 24, 2026 @09:36AM (#47137689)
When the condition for when you want to replace is hard to properly specify, AI shines for such find and replaces.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by Aachen on Tuesday February 24, 2026 @10:04AM (#47138054)
This one is literally matching "innerHTML = X" and setting "setHTML(X)" instead. Not some complex data format transformation

But I can see what you mean, even if then it would still be better for it to print the code that does what you want (uses a few Wh) than doing the actual transformation itself (prone to mistakes, injection attacks, and uses however many tokens your input data is)

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by charcircuit on Tuesday February 24, 2026 @11:18AM (#47138948)
That can break the site if you do the find and replace blindly. The goal here is to do the refactor without breaking the site.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by lelanthran on Tuesday February 24, 2026 @01:24PM (#47140667)
> When the condition for when you want to replace is hard to properly specify, AI shines for such find and replaces.

And, in your opinion, this is one of those cases?

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by charcircuit on Tuesday February 24, 2026 @05:35PM (#47144299)
It is because the new API purposefully blocks things the old API did not.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by littlestymaar on Tuesday February 24, 2026 @10:39AM (#47138523)
This ship has sailed unfortunately, no later than yesterday I've seen coworkers redact a screenshot using chatGTP.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by josefx on Tuesday February 24, 2026 @09:15AM (#47137426)
Wouldn't AI be trained on data using innerHTML?
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by Aachen on Tuesday February 24, 2026 @09:35AM (#47137675)
My experience is that they somehow print quite modern code despite things like ES6 being too new to be standard knowledge even for me and I'm not even middle-aged yet

Maybe the last 10 years saw so much more modern code than the last cumulative 40+ years of coding and so modern code is statistically more likely to be output? Or maybe they assign higher weights to more recent commits/sources during training? Not sure but it seems to be good at picking this up. And you can always feed the info into its context window until then

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by skeeter2020 on Tuesday February 24, 2026 @10:15AM (#47138206)
This is not my experience. Claude has been happily generating code over the past week that is full of implicit any and using code that's been deprecated for at least 2 years.

>> Maybe the last 10 years saw so much more modern code than the last cumulative 40+ years of coding and so modern code is statistically more likely to be output?

The rate of change has made defining "modern" even more difficult and the timeframe brief, plus all that new code is based on old code, so it's more like a leaning tower than some sort of solid foundation.

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by SahAssar on Tuesday February 24, 2026 @11:53AM (#47139370)
ES6 is 11 years old. It's not that new.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by Aachen on Wednesday February 25, 2026 @08:35AM (#47151266)
Hence the example of how long it takes non-LLMs to pick that up, whereas LLMs seem to get it despite there being loads of old code out there

See also my reply to the sibling comment with the same remark https://news.ycombinator.com/item?id=47151211

My mistake for saying 10 instead of 11 years btw, but I don't think it changes the point

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by chrisweekly on Tuesday February 24, 2026 @12:53PM (#47140200)
> "ES6 being too new to be standard knowledge"

Huh? It's been a decade.

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by Aachen on Wednesday February 25, 2026 @08:29AM (#47151211)
Exactly, I learned coding JS before 2015 (it was my first language, picked up during what is probably called middle school in english). I haven't had to learn it again from scratch, so I need to go out of my way to find if there is maybe a better way to do the thing I can already do fine. It's not automatic knowledge, yet the LLM seems to have no trouble with it, so I'm pointing out that they seem to not have problems upgrading. The grandparent comment suggested it would need to be trained anew to use this new method instead. Given how much old (non-ES6) JS there is, apparently it gets it quite easily so any update that includes some amount of this new code will probably do it just fine
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by charcircuit on Tuesday February 24, 2026 @09:37AM (#47137700)
Which is why it can easily understand how innerHTML is being used so that it can replace it with the right thing.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by stvltvs on Tuesday February 24, 2026 @09:37AM (#47137703)
Honest question: Is there a way to get an LLM to stop emitting deprecated code?
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by fragmede on Tuesday February 24, 2026 @09:39AM (#47137740)
Theoretically, if you could train your own, and remove all references to the deprecated code in the training data, it wouldn't be able to emit deprecated code. Realistically that ability is out of reach at the hobbiest level so it will have to remain theoretical for at least a few more iterations of Moore's law.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by jaffathecake on Tuesday February 24, 2026 @09:54AM (#47137913)
fwiw, if you serve your page with:

Content-Security-Policy: require-trusted-types-for 'script'

…then it blocks you from passing regular strings to the methods that don't sanitize.

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by onion2k on Tuesday February 24, 2026 @11:35AM (#47139153)
it's not at all clear which is which from the names

There's setHTML and setHTMLUnsafe. That seems about as clear as you can get.

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by entuno on Tuesday February 24, 2026 @12:16PM (#47139695)
If that'd been the design from the start, then sure. But it's not at all obvious that setHTML is safe with arbitrary user input (for a given value of "safe") and innerHTML is dangerous.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by hahn-kev on Tuesday February 24, 2026 @11:40AM (#47139222)
But you can use InnerHTML to set HTML and that's not safe.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by onion2k on Tuesday February 24, 2026 @12:41PM (#47140053)
At this point that API has been around for decades and is probably impossible to deprecate without breaking fairly large amounts of the web. The only option is to introduce a new and better API, and maybe eventually have the browser throw out console warnings if a page still uses the old innerHTML API. I doubt any browser vendor will be gung ho enough to actually remove it for a very long time.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by DoctorOW on Tuesday February 24, 2026 @08:59AM (#47137253)
They do link the default configuration for "safe": https://wicg.github.io/sanitizer-api/#built-in-safe-default-...

But I agree, my default approach has usually been to only use innerText if it has untrusted content:

So if their demo is this:

    container.SetHTML(`<h1>Hello, {name}</h1>`);
Mine would be:

    let greetingHeader = container.CreateElement("h1");
    greetingHeader.innerText = `Hello, {name}`;
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by itishappy on Tuesday February 24, 2026 @09:58AM (#47137954)
What if I wanted an <h2>?

Edit: I don't mean this flippantly. If I want to render, say, my blog entry on your site, will I need to select every markup element from a dropdown list of custom elements that only accept text a la Wordpress?

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by DoctorOW on Tuesday February 24, 2026 @05:28PM (#47144220)
If it's anything complex I'm doing it server side, personally
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by itishappy on Tuesday February 24, 2026 @10:23PM (#47146891)
That works fine. That said, client side JS solutions are already quite popular.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by noduerme on Tuesday February 24, 2026 @09:07AM (#47137325)
Some sanitization is better than none? If you're relying on the browser to handle it for you, you're already in a lot of trouble.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by post-it on Tuesday February 24, 2026 @08:59AM (#47137254)
realSetSafeHTML()
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by HWR_14 on Tuesday February 24, 2026 @12:30PM (#47139899)
That's why I only allow user input of alphanumeric ascii characters. No need to worry about sanitation then, and you can just remove all the characters that don't match.

(It's a joke, but it is also 100% XSS, SQL injection, etc. safe and future proof)

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by thaumasiotes on Tuesday February 24, 2026 @03:27PM (#47142452)
> I'm also rather sceptical of things that "sanitise" HTML, both because there's a long history of them having holes, and because it's not immediately clear what that means, and what exactly is considered "safe".

What is safe depends on where the sanitized HTML is going, on what you're doing with it.

It isn't possible to "sanitize HTML" after collecting it so that, when you use it in the future, it will be safe. "Safe" is defined by the use.

But it is possible to sanitize it before using it, when you know what the use will be.

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by cxr on Tuesday February 24, 2026 @03:34PM (#47142569)
> it's not at all clear which is which from the names. Ideally you design that in from the [start]

It was, and there is: setting elementNode.textContent is safe for untrusted inputs, and setting elementNode.innerHTML is unsafe for untrusted inputs. The former will escape everything, and the latter won't escape anything.

You are right that these "sanitizers" are fundamentally confused:

> "HTML sanitization" is never going to be solved because it's not solvable.¶ There's no getting around knowing whether or any arbitrary string is legitimate markup from a trusted source or some untrusted input that needs to be treated like text. This is a hard requirement.

<https://news.ycombinator.com/item?id=46222923>

The Web platform folks who are responsible for getting fundamental APIs standardized and implemented natively are in a position to know better, and they should know better. This API should not have made it past proposal stage and should not have been added to browsers.

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by Dylan16807 on Tuesday February 24, 2026 @04:13PM (#47143136)
> There's no getting around knowing whether or any arbitrary string is legitimate markup from a trusted source or some untrusted input that needs to be treated like text. This is a hard requirement.

It is not a hard requirement that untrusted input is "treated like text". And this API lets you customize exactly what tags/attributes are allowed in the untrusted input. That's way better than telling everyone to write their own; it's not trivial.

[dead]
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by Dylan16807 on Tuesday February 24, 2026 @04:40PM (#47143533)
I don't see how I differed from what you said? You divided strings going into HTML into two categories, where one category uses textContent and the other category uses innerHTML. My point is to disagree with those categories, not whatever subtle thing you're taking issue with.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by cxr on Tuesday February 24, 2026 @04:46PM (#47143630)
Oh, okay. Tell me, dipshit, are the follow two claims equivalent or different?:

"Everyone who files a tax return should know whether they need to pay at least $1000 in unpaid taxes to the IRS."

"Everyone who files a tax return needs to pay at least $1000 in unpaid taxes to the IRS."

> You divided strings going into HTML into two categories, where one category uses textContent and the other category uses innerHTML.

No, I didn't:

> setting elementNode.textContent is safe for untrusted inputs, and setting elementNode.innerHTML is unsafe for untrusted inputs

That's what I wrote: a statement containing two claims (both true—and not even in the part of my comment that you actually quoted and pretended to be replying to).

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by Dylan16807 on Tuesday February 24, 2026 @05:02PM (#47143862)
This is a totally different kind of statement. You're not dividing tax returns into two categories and then saying what to do with each category.

Those claims are different but not in a way that analogizes to the HTML conversation.

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by cxr on Tuesday February 24, 2026 @05:11PM (#47143995)
I'd say I'm interested in hearing how you reason that knowing whether you need to pay at least $1000 in unpaid taxes to the IRS doesn't put you in one bucket or another, but I'm not.
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by Dylan16807 on Tuesday February 24, 2026 @05:39PM (#47144354)
The IRS thing indirectly has categories but it doesn't say what to do with them, and what to do with them is what I disagreed with your original post on. I didn't say all input is untrusted or whatever analogizes to your tax thing.

Anyway, I see you edited your previous post after I wrote my reply.

If you weren't trying to divide things into two categories, you wrote it very confusingly. When you say how to handle trusted strings, then say how to handle untrusted strings, then say "There's no getting around knowing whether or any arbitrary string is legitimate markup from a trusted source or some untrusted input that needs to be treated like text. This is a hard requirement." it really sounds like that's supposed that's supposed to cover all cases.

Me thinking you were using two categories is an honest mistake, not malicious misquoting.

And reading your original post that way is the interpretation that makes it stronger. If there are more categories then SetHTML is no longer "fundamentally confused". Your argument against it falls apart.

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by cxr on Tuesday February 24, 2026 @06:40PM (#47145153)
Guess how interested I am in pretending that a debate with you—about this or anything else—is worthwhile (or anything, really, other than an even bigger waste of time than it already has been).
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by cxr on Tuesday February 24, 2026 @06:57PM (#47145322)
It is not a hard requirement that untrusted input is "treated like text".

It's also not a hard requirement that I defend the position that there's a hard requirement for untrusted input to be treated like text. That isn't my position, and it's not what I wrote.

Given that it is not a hard requirement that untrusted input be treated like text, it wouldn't make sense for anyone to claim that it is—and therefore it doesn't make sense for someone, presented with I did write, to strenuously argue with me that such a tortured, implausible, uncharitable, non-sensical interpretation of what I wrote was something that I have to account for (versus the interpretation that does match what I wrote and is actually true and makes sense).

You are, willfully or not, misconstruing what I have written.

> That's way better than telling everyone to write their own; it's not trivial.

Right, it's not trivial. It's so far the opposite of trivial that it's (as I said the first time—and again, just now) not solvable.

No one should be writing their own.

No one should be trying to write their own.

No one should be using this API at all.

And no one should have pushed for its implementation.

It's a bad API.

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by Dylan16807 on Tuesday February 24, 2026 @07:22PM (#47145577)
I thought you were done talking to me?

Briefly though, if you have an untrusted string then you need to either treat it like text or sanitize it. I don't see any other options.

So if people shouldn't use this sanitizer or write their own, then the only option left is treating the string as text. But you're vehemently arguing that's not what you said.

What's the other way to use an untrusted string? Other than "don't", but that means not taking input and only works for toy apps.

Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by cxr on Friday February 27, 2026 @04:13PM (#47185698)
[delayed]
Re:Goodbye InnerHTML, Hello SetHTML: Stronger XSS Protection... by duxup on Tuesday February 24, 2026 @10:25PM (#47146911)
Yeah someone tells me something has been made “safe” is nice but unless I know exactly what that means … it’s easy to say safe by someone who doesn’t have to deal with it when the bad corner case happens.

Oh and it’s safe… in this browser… not that one, so this idea of safety is kinda dead to me for now.