News for hackers. Stuff that matters.
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.