logoalt Hacker News

dllulast Thursday at 7:45 PM20 repliesview on HN

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.


Replies

poormanlast Thursday at 8:08 PM

All SVGs should be properly sanitized going into a backend and out of it and when rendered on a page.

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.

show 5 replies
aidenn0last Thursday at 8:30 PM

External entities in XML[1] were a similar issue back when everyone was using XML for everything, and parsers processed external-entities by default.

1: https://owasp.org/www-community/vulnerabilities/XML_External...

show 2 replies
socalgal2yesterday at 6:19 AM

IIUC, an untrusted inline SVG is bad. An image tag pointing to an SVG is not.

    <img src="untrusted.svg"> <!-- this is ok -->
    <svg from untrusted src>  <!-- this is not ok -->
I feel like this is common knowledge. Just like you don't inject untrusted HTML into your page. Untrusted HTML also has scripts. You either sanitize it. OR you just don't allow it in the first place. SVG is, at this point, effectively more HTML tags.
show 1 reply
bobbylarrybobbylast Thursday at 8:03 PM

Would it be possible for messenger apps to simply ignore <script> tags (and accept that this will break a small fraction of SVGs)? Or is that not a sufficient defense?

show 2 replies
Wowfunhappylast Thursday at 9:49 PM

IMO, the bigger problem with SVGs as an image format is that different software often renders them (very) differently! It's a class of problem that raster image formats basically don't have.

show 3 replies
IgorPartolayesterday at 12:14 AM

But how else would we revisit all the security bugs of Flash/Macromedia?

HPsquaredlast Thursday at 9:02 PM

Could there be a limited format that disables scripting? Like in Excel: xlsx files have no macros, but xlsm (and the old xls) can contain macros.

nightskilast Thursday at 8:02 PM

Does it need to be as complicated as a new format? Or would it be enough to not allow any scripting in the provided SVGs (or stripping it out). I can't imagine there are that many SVGs out there which take advantage of the feature.

Gander5739last Thursday at 11:18 PM

Wikipedia, which allows uploading media, deals with this by rendering svgs on the server side.

FeepingCreaturelast Thursday at 8:05 PM

If only there was a widely used vector format that had script support and also decades of work on maintaining a battle-tested security layer around it with regular updates on a faster release cycle than your browser. That'd be crazy. Sure would suck if we killed it because we didn't want to bother maintaining it anymore.

(Yes I'm still salty about Flash.)

show 3 replies
css_apologistlast Thursday at 9:50 PM

is santizing SVGs hard, or just everyone forgets they can contain js?

show 2 replies
Pxtlyesterday at 12:51 PM

What we got was html for vector graphics and what we wanted was jpeg for vector graphics.

hoppplast Thursday at 9:51 PM

I agree, when animating SVGs I never put the js inside them so having the ability embed it is just dangerious I think

culilast Thursday at 8:02 PM

Do other vector formats have the same vulnerabilities?

msielast Thursday at 8:37 PM

Wow, I learned one thing today!

username223last Thursday at 8:30 PM

It's wild how often we rediscover that executing untrusted code leads to decades of whack-a-mole security. Excel/Word plus macros, HTML plus JavaScript, SVG plus JavaScript, ...

show 1 reply
fainpullast Thursday at 8:15 PM

"The script doesn't run unless the file is directly opened (you can't run scripts from (<img src="/image.svg">)."

show 1 reply
aydynlast Thursday at 8:36 PM

There is: PDF. You may not like it or adobe, but its there and widely supported.

show 2 replies
SV_BubbleTimelast Thursday at 8:10 PM

> On one hand, the animations and entire interactive demos and even games in a single SVG are cool. But on the other hand

Didn’t we do this already with Flash? Why would this lesson not have stuck?