News for hackers. Stuff that matters.
Re:The Woes of Sanitizing SVGs by andybak on Monday April 27, 2026 @11:55AM (#47923270)
My first thought is "support a tiny subset of svg that probably still covers 90% of real-world use cases".

I do feel that's there's two distinct types of svg - "bunch of paths with fills" and "clever dangerous stuff" where most real SVGs are of the former type.

Fully expect this to be shot down by someone that's thought about this problem for longer than the 120 seconds I just spent. :)

Re:The Woes of Sanitizing SVGs by duped on Monday April 27, 2026 @12:19PM (#47923593)
So if you are building something where you control every SVG ever produced and rendered then this is totally reasonable.

If you ever need to interface with other tools that generate SVG you now need to have a way of essentially transpiling SVG from the wild into your tamed SVGs. Oftentimes this is done by hand, by a software developer and designer (sometimes the same person).

And this is for basic functionality that your designers expect and have trivial controls for in their vector editors, like "add a drop shadow."

The article goes into some issues with sanitization itself, and except for <script> these are a bunch of reasonable things that someone might expect to work or not have issues with. Sandboxing rendering isn't an unreasonable approach if you're not writing the parser and renderer yourself.

Re:The Woes of Sanitizing SVGs by varun_ch on Monday April 27, 2026 @12:02PM (#47923355)
I wonder if it would be best if this was at the browser level as some sort of new format. Otherwise surely it would be really slow/cumbersome to deal with these in ‘user space’
Re:The Woes of Sanitizing SVGs by harperlee on Monday April 27, 2026 @11:57AM (#47923300)
Fwiw I just thought the same, parse (don’t validate) the bits you like and recreate / reject the input.
Re:The Woes of Sanitizing SVGs by whycome on Monday April 27, 2026 @12:23PM (#47923632)
It always seems like any animated svg loses all of the animation after sanitizing
Re:The Woes of Sanitizing SVGs by bawolff on Monday April 27, 2026 @03:24PM (#47926113)
There are 3 different methods of animating svgs so it probably depends.
Re:The Woes of Sanitizing SVGs by RobotToaster on Tuesday April 28, 2026 @02:31AM (#47931060)
A lot of SVG animation uses JS for some reason. It would be interesting to see if sanitisers strip CSS and SMIL animation, I don't see any security reasons to do so.
Re:The Woes of Sanitizing SVGs by afavour on Monday April 27, 2026 @12:24PM (#47923659)
I think you're right but the lack of industry standard for this kind of thing kills it. People want to be able to take the output of whatever tool they use that exports SVG and put it in a browser. Which isn't an unfair request. But you wouldn't have a guarantee it wouldn't filter out the tool using some obscure SVG functionality.

I'd love to see an agreed standard like OpenGL vs OpenGL ES for SVG. SVG-ES. Everyone agrees on the static, non-scripted elements that should work.

Re:The Woes of Sanitizing SVGs by varun_ch on Monday April 27, 2026 @12:28PM (#47923710)
The way linked SVGs render from within img tags is basically perfect for SVG images (which as I understand is not standardized but is largely the same across browsers). External resources and scripting are blocked while still rendering nearly all SVGs correctly. And of course, any CSS is scoped to the SVG.

If someone formalizes this as a new format, please give it a new name! tvg tiny vector graphics? savg safe vector graphics?

And keep the scope as simple as possible so it actually ships! Don’t try implementing a binary format or something.

Re:The Woes of Sanitizing SVGs by hackeman300 on Monday April 27, 2026 @12:35PM (#47923832)
Someone did this already and did call it tinyVG! https://tinyvg.tech/
Re:The Woes of Sanitizing SVGs by sbrother on Monday April 27, 2026 @02:08PM (#47925117)
Maybe I'm missing something as I am not a frontend developer, but when you embed SVGs in an img tag as part of a Phoenix LiveView or even just a static component, you no longer get the ability to dynamically change paths/fills/colors with events coming from the server. Even if it's as simple as having a shape that you want to fill with a brand/highlight color, which at least for me is a common use case.
Re:The Woes of Sanitizing SVGs by ambicapter on Monday April 27, 2026 @12:32PM (#47923786)
.rvg, Restricted Vector Graphics?
Re:The Woes of Sanitizing SVGs by LorenPechtel on Monday April 27, 2026 @12:31PM (#47923765)
Yeah, I think that's the real answer.

Look at what Microsoft did with Excel--the dangerous stuff is behind a switch.

Thus, solution:

Add two bits to the tag.

SVG1 does not execute any sort of script.

SVG2 does not follow links.

SVG3 is actually SVG1 + SVG2 as these are bit flags, not numbers.

Additional bits are reserved for future use if any other issues are found.

The only real safety is in the engine, not by any sanitizer.

Re:The Woes of Sanitizing SVGs by bawolff on Monday April 27, 2026 @03:26PM (#47926137)
Which is essentially already how it works. See https://svgwg.org/specs/integration/#secure-animated-mode
Re:The Woes of Sanitizing SVGs by cachius on Monday April 27, 2026 @02:42PM (#47925520)
What switch?
Re:The Woes of Sanitizing SVGs by LorenPechtel on Tuesday April 28, 2026 @04:52PM (#47940578)
Whether macros are enabled.
Re:The Woes of Sanitizing SVGs by hackeman300 on Monday April 27, 2026 @12:35PM (#47923816)
Seems like someone already implemented your idea. https://tinyvg.tech/
Re:The Woes of Sanitizing SVGs by codedokode on Tuesday April 28, 2026 @12:30AM (#47930470)
Maybe we could use a subset of SVG or PDF?
Re:The Woes of Sanitizing SVGs by RobotToaster on Monday April 27, 2026 @01:57PM (#47924968)
You'd lose a lot of useful features, like SMIL animation.
Re:The Woes of Sanitizing SVGs by andybak on Monday April 27, 2026 @02:02PM (#47925019)
But you'd gain adoption. A fair trade.
Re:The Woes of Sanitizing SVGs by bawolff on Monday April 27, 2026 @03:11PM (#47925925)
> My first thought is "support a tiny subset of svg that probably still covers 90% of real-world use cases".

It sounds like the linked post was about someone using a blacklist instead of a whitelist. It doesnt matter how tiny your subset is if you allow through stuff you don't recognize.

For the most part svg is safe. The dangerous parts are pretty obvious - script tag, image tag, feImage tag, attributes starting with on, embedding html in <foreignObject>, DTD tricks, namespace tricks, CSS that loads external stuff (keep in mind also presentational attributes. Its not just style attribute/tag).

The rest of it is pretty safe.

Re:The Woes of Sanitizing SVGs by Avamander on Monday April 27, 2026 @03:32PM (#47926208)
There's the SVG Tiny profile that some implementations use, like BIMI/VMCs.
Re:The Woes of Sanitizing SVGs by pupppet on Monday April 27, 2026 @04:03PM (#47926604)
This is what happens when there isn't an adult in the room to reign things in, you get project overreach. SVGs should never have supported scripting. You want scripting in SVGs, fine, make it a different file format.

I can't imagine the cumulative number of man hours wasted on this problem when the vast majority of users were just looking for a way to make their logos look sharp.

Re:The Woes of Sanitizing SVGs by thrance on Monday April 27, 2026 @04:41PM (#47927044)
Or you can literally just manipulate your SVG through the DOM in an external JS script... I still have no idea what the original motivation behind scripts in SVGs was.
Re:The Woes of Sanitizing SVGs by bobthepanda on Monday April 27, 2026 @05:03PM (#47927280)
I imagine it may have been attractive to those who liked Flash.
Re:The Woes of Sanitizing SVGs by oldsecondhand on Monday April 27, 2026 @09:37PM (#47929534)
OG actionscript was very similar to Javascript. It only started to diverge when type hints were introduced.
Re:The Woes of Sanitizing SVGs by gsnedders on Monday April 27, 2026 @11:29PM (#47930183)
AS2 was mostly following the direction of ES4 — so it wouldn’t have diverged if it hadn’t been abandoned.
Re:The Woes of Sanitizing SVGs by pbhjpbhj on Tuesday April 28, 2026 @03:53AM (#47931600)
I think it may have been the other way (ie attractive to those who didn't like flash) - SVG was seen as a potential flash replacement?
Re:The Woes of Sanitizing SVGs by kilna on Tuesday April 28, 2026 @11:55AM (#47936233)
> SVG was seen as a potential flash replacement?

Yes, that was a large part of the thrust back in the day. Even if it wasn't officially a goal of the SVG working group, there was a lack of an open standards-based alternative to what Flash was able to do, and the developers of the SVG standard saw that adding animation/tweening wouldn't take much given what browsers were already becoming capable of.

Re:The Woes of Sanitizing SVGs by bobthepanda on Tuesday April 28, 2026 @12:51PM (#47937077)
a little bit of a, a little bit of b. to displace flash if you don't like it, SVG has to have flash-like features to appeal to those who do use it and steal them away.
Re:The Woes of Sanitizing SVGs by zarzavat on Monday April 27, 2026 @08:18PM (#47928941)
While SVG is a web technology, for the longest time you had to install SVG support as a browser plug-in. I remember installing Adobe SVG viewer around 2000. It was used for interactive visualizations.

I'm don't remember precisely but I don't think you could script it from the DOM, I don't see how that could work if it's a plugin.

Re:The Woes of Sanitizing SVGs by NL807 on Monday April 27, 2026 @10:18PM (#47929808)
> SVGs should never have supported scripting.

I would even go further: HTML should never have supported scripting.

Re:The Woes of Sanitizing SVGs by throwawayqqq11 on Tuesday April 28, 2026 @12:50AM (#47930557)
... or third party requests. Scratch the H in HTML and internet tracking would have never happened.
Re:The Woes of Sanitizing SVGs by philipallstar on Tuesday April 28, 2026 @06:46AM (#47932661)
You could track people without links. You just couldn't go to other places without links.
Re:The Woes of Sanitizing SVGs by nine_k on Monday April 27, 2026 @09:56PM (#47929671)
I would say that a proper sanitizer should remove any attribute that has /https?:/ in it. Maybe it should allow access to a subtree of a blessed domain you control, where stuff like textures is stored.
Re:The Woes of Sanitizing SVGs by Nursie on Monday April 27, 2026 @10:17PM (#47929802)
SVG Tiny PS (Portable Secure) is an attempt at this - https://www.ietf.org/archive/id/draft-svg-tiny-ps-abrotman-0...

Though I think it's still a draft, it does appear to be a requirement for BIMI - https://en.wikipedia.org/wiki/Brand_Indicators_for_Message_I...

Re:The Woes of Sanitizing SVGs by 0x1ceb00da on Tuesday April 28, 2026 @12:21AM (#47930421)
This is what android does. It has its own vector asset format and android studio has an action for importing svgs.
Re:The Woes of Sanitizing SVGs by gardaani on Tuesday April 28, 2026 @03:42AM (#47931508)
W3C has been defining SVG Native, but it hasn't progressed much lately — mostly because there hasn't been any interest in it. SVG Native is a small subset of SVG 2.0 which doesn't support scripting, animations or any external references. https://svgwg.org/specs/svg-native/
Re:The Woes of Sanitizing SVGs by kilna on Tuesday April 28, 2026 @11:46AM (#47936118)
The rust resvg [1] project uses micro SVG (usvg) [2] as an interim normalization format that simplifies SVG into solely:

* Simplified paths (no shapes, only one kind of object)

* DTDs, Attributes, CSS and references are pre-resolved

* Invisible elements and comments are removed

Resolving shared items may cause sizes to increase drastically however. This is the sort of explosion that compression is perfect at compressing.

1: https://docs.rs/resvg/latest/resvg/ 2: https://docs.rs/usvg/latest/usvg/