(no title)
entuno | 5 days ago
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".
entuno | 5 days ago
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".
jncraton|5 days ago
[1] https://developer.mozilla.org/en-US/docs/Web/API/Element/set...
entuno|5 days ago
intrasight|5 days ago
cxr|5 days ago
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.
Dylan16807|5 days ago
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.
voxic11|5 days ago
extraduder_ire|5 days ago
Good idea to ship that one first, when it's easier to implement and is going to be the unsafe fallback going forward.
croes|5 days ago
reddalo|5 days ago
post-it|5 days ago
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.
Cthulhu_|5 days ago
cxr|5 days ago
> set a global property somewhere (as a web developer) that disallows[…] `innerHTML`
(Not that you should actually do this—anyone who has to resort to it in their codebase has deeper problems.)staticassertion|5 days ago
afavour|5 days ago
jaffathecake|5 days ago
Content-Security-Policy: require-trusted-types-for 'script'
…then it blocks you from passing regular strings to the methods that don't sanitize.
thaumasiotes|5 days ago
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.
DoctorOW|5 days ago
But I agree, my default approach has usually been to only use innerText if it has untrusted content:
So if their demo is this:
Mine would be:itishappy|5 days ago
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?
duxup|5 days ago
Oh and it’s safe… in this browser… not that one, so this idea of safety is kinda dead to me for now.
HWR_14|5 days ago
(It's a joke, but it is also 100% XSS, SQL injection, etc. safe and future proof)
noduerme|5 days ago
post-it|5 days ago
unknown|5 days ago
[deleted]
snowhale|5 days ago
[deleted]
pornel|5 days ago
Don't even try to allow inline <svg> from untrusted sources! (and then you still must sanitise any svg files you host)
cxr|5 days ago
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 between the two 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.
onion2k|5 days ago
There's setHTML and setHTMLUnsafe. That seems about as clear as you can get.
entuno|5 days ago
hahn-kev|5 days ago