The fact that SVG files can contain scripts was a bit of a mistake. On one hand, the animations and entire interactive demos and even games in a single SVG are cool. But on the other hand, it opens up a serious can of worms of security vulnerabilities. As a result, SVG files are often banned from various image upload tools, they do not unfurl previews, and so on. If you upload an SVG to discord, it just shows the raw code; and don't even think about sharing an SVG image via Facebook Messenger, Wechat, Google Hangouts, or whatever. In 2025, raster formats remain way more accessible and easily shared than SVGs.This is very sad because SVGs often have way smaller file size, and obviously look much better at various scales. If only there was a widely used vector format that does not have any script support and can be easily shared.
poorman|2 months ago
Do you allow SVGs to be uploaded anywhere on your site? This is a PSA that you're probably at risk unless you can find the few hundred lines of code doing the sanitization.
Note to Ruby on Rails developers, your active storage uploaded SVGs are not sanitized by default.
nradov|2 months ago
codedokode|2 months ago
poorman|2 months ago
rcxdude|2 months ago
ivw|2 months ago
aidenn0|2 months ago
1: https://owasp.org/www-community/vulnerabilities/XML_External...
Sohcahtoa82|2 months ago
Whoever decided it should be enabled by default should be put into some sort of cybersecurity jail.
hinkley|2 months ago
socalgal2|2 months ago
auxiliarymoose|2 months ago
That SVG can then do things like history.replaceState() and include <foreignObject> with HTML to change the URL shown to the user away from the SVG source and show any web UI it would like.
bobbylarrybobby|2 months ago
demurgos|2 months ago
The only reliable solution would be an allowlist of safe elements and attributes, but it would quickly cause compat issues unless you spend time curating the rules. I did not find an existing lib doing it at the time, and it was too much effort to maintain it ourselves.
The solution I ended up implementing was having a sandboxed Chromium instance and communicating with it through the dev tools to load the SVG and rasterize it. This allowed uploading SVG files, but it was then served as rasterized PNGs to other users.
staticassertion|2 months ago
But you can use an `img` tag (`<img src="evil.svg">`) and that'll basically Just Work, or use a CSP. I wouldn't rely on sanitizing, but I'd still sanitize.
Wowfunhappy|2 months ago
josefx|2 months ago
That took way too long to be this way. Some old browsers couldn't even get the colors of PNGs correct, let alone the transparency.
zffr|2 months ago
VBprogrammer|2 months ago
HPsquared|2 months ago
IgorPartola|2 months ago
username223|2 months ago
eastbound|2 months ago
It’s so regular like clockwork that it has to be a nation state doing this to us.
nightski|2 months ago
FeepingCreature|2 months ago
(Yes I'm still salty about Flash.)
JoshTriplett|2 months ago
That wasn't the only reason. Flash was also proprietary, and opaque, and single-vendor, among many other problems with it.
ajross|2 months ago
lambdaone|2 months ago
Pxtl|2 months ago
Gander5739|2 months ago
zahlman|2 months ago
Anyway, I just set `svg.disabled` in Firefox. Scary world out there.
zahlman|2 months ago
css_apologist|2 months ago
rslashuser|2 months ago
I guess the next step is to propose a simple "noscripting" attribute, which if present in the root of the SVG doc inhibits all scripting by conforming renderers. Then the renderer layer at runtime could also take a noscripting option, so the rendering context could force it if appropriate. Surely someone at HN is on this committee, so see what you can do!
Edit: thinking about it a little more - maybe it's best to just require noscripting as a parameter to the rendering function. Then the browsers can have a corresponding checkbox to control SVG scripting and that's it.
AmbroseBierce|2 months ago
SV_BubbleTime|2 months ago
Didn’t we do this already with Flash? Why would this lesson not have stuck?
hoppp|2 months ago
msie|2 months ago
unknown|2 months ago
[deleted]
culi|2 months ago
fainpul|2 months ago
kevin_thibedeau|2 months ago
aydyn|2 months ago
Shared404|2 months ago
anthk|2 months ago