News for hackers. Stuff that matters.
Re:CSS in GitHub Readmes by kodah on Tuesday December 08, 2020 @01:26PM (#25349362)
Can't SVG's also be used to run code?

Yes, you can: https://stackoverflow.com/questions/5378559/including-javasc...

brb as I write a follow up article.

Re:CSS in GitHub Readmes by NiekvdMaas on Tuesday December 08, 2020 @02:37PM (#25350248)
GitHub uses Camo [1] to serve assets like images and SVG files. It removes any "dangerous" code like JS from the file before serving it from a GitHub CDN.

1. https://github.com/atmos/camo

Re:CSS in GitHub Readmes by buro9 on Tuesday December 08, 2020 @03:14PM (#25350729)
Are you sure?

Yes they use Camo, but that's a proxy to ensure that you don't serve JS from the same domain as github.com so that 3rd party assets have the JavaScript domain security policy applied.

I do not believe that Camo is a sanitising proxy... just a proxy.

Re:CSS in GitHub Readmes by kebman on Tuesday December 08, 2020 @04:50PM (#25351856)
Oh my! Never knew SVG was such a rabbit hole lol! Thanks for this info!
Re:CSS in GitHub Readmes by wruza on Tuesday December 08, 2020 @03:03PM (#25350601)
Ah svg, reminds me these fine windows metafile days.

Seriously, can we stop inventing formats that execute arbitrary code under the hood?

Re:CSS in GitHub Readmes by colejohnson66 on Tuesday December 08, 2020 @03:10PM (#25350675)
The problem isn’t SVG necessarily. It’s a nice vector format with many hidden features available to those who explore (especially with SVG 2 around the corner). The problem is JavaScript. Unfortunately, there’s not much one can do if they want interactive images[a][b] short of a Turing Complete language. And if you’re going to need that, JavaScript’s right there (for better or for worse).

[a]: Embedding the SVG directly into the HTML and manipulating it using the JavaScript in the HTML is an option, but not many people do that

[b]: We can argue all we want about whether we should be making interactive images in the first place, but the fact of the matter is, either you add it to your format, or someone else will

Re:CSS in GitHub Readmes by eyelidlessness on Tuesday December 08, 2020 @06:45PM (#25353232)
Every time someone does, someone else comes along and either presents a compelling enough use case that arbitrary execution is introduced or just wraps the thing in an environment where it’s funneled in.
Re:CSS in GitHub Readmes by gitgud on Tuesday December 08, 2020 @04:49PM (#25351839)
Can svg's even do anything malicious with that capability?
Re:CSS in GitHub Readmes by eyelidlessness on Tuesday December 08, 2020 @06:46PM (#25353246)
Where they can execute JS, they can do so in the same security context as the containing document. So, yeah, they can be used in situ for any privacy or security intrusion that a script tag can.
Re:CSS in GitHub Readmes by felixfbecker on Wednesday December 09, 2020 @06:50AM (#25357649)
This is not entirely correct. An SVG file embedded in an <iframe> or <object> is a document itself, and if cross-origin, can not access the outer document. However, if not in a sandboxed iframe, it can still do things like trigger alert prompts or navigation.
Re:CSS in GitHub Readmes by eyelidlessness on Wednesday December 09, 2020 @09:42AM (#25358920)
Sorry, this is right. I should have said it’s just as capable or limited in SVG as a bare script tag in the same place.
Re:CSS in GitHub Readmes by wut42 on Wednesday December 09, 2020 @08:09AM (#25358084)
Camo is just a proxy that allows them to (a) always serve remote content from HTTPS and (b) more constrained CSP rules. Camo doesn't remove any code nor sanitize it.

Edit: I think I narrowed down where you were wrong! Github "raw" endpoints for repository files DOES have a sanitizing option. But that's not Camo (camo is for remote, non repo, assets (linked in comments or in markdown)).

Re:CSS in GitHub Readmes by porphyra on Tuesday December 08, 2020 @02:52PM (#25350440)
I think allowing scripts and stuff in SVGs was a huge mistake that is why they are still not widely supported yet. For example you can't upload or send SVGs as images in typical messaging services or image sharing sited, in part because it would be a security vulnerability.

But as a consequence now we (still) have no easily portable vector format :'(

Re:CSS in GitHub Readmes by identity0 on Tuesday December 08, 2020 @11:21PM (#25355325)
SVG is still a stupid format. Who wants to send image data through XML? It would be like sending a raster image through a big JSON array.
Re:CSS in GitHub Readmes by onion2k on Wednesday December 09, 2020 @04:24AM (#25356807)
Who wants to send image data through XML?

SVGs aren't image data. They're a set of instructions for recreating image data using a structured language. XML is very good for data like that.

Re:CSS in GitHub Readmes by porphyra on Wednesday December 09, 2020 @01:12PM (#25361659)
Text-based formats like XML and JSON are good if most of your data is strings, but storing numeric data in decimal strings is both inefficient and inaccurate. That's why I think that HTML is an appropriate use of XML-like markup but perhaps vector images would need a true binary version.

However I agree with saagarjha that it is very easy to write code to emit SVG, which is nice.

Re:CSS in GitHub Readmes by saagarjha on Wednesday December 09, 2020 @06:41AM (#25357602)
And their text format is exceedingly useful if you're writing code to generate them.
Re:CSS in GitHub Readmes by IshKebab on Wednesday December 09, 2020 @05:29PM (#25366204)
I don't think it would really be any more difficult if it were binary. The only real reason to use XML is better integration with HTML, CSS and JavaScript, which is admittedly a compelling reason.

But I think he's right - it would be nice if there was a "proper" binary vector format that was widely supported.

Re:CSS in GitHub Readmes by saagarjha on Thursday December 10, 2020 @02:28PM (#25377462)
I mean, I can write a line of Python that goes

  print(f"""<rect x="{x}" y="{y}" width="{w}" height="{h}"/>""")
I find this eminently easier than working with a binary format.
Re:CSS in GitHub Readmes by IshKebab on Friday December 11, 2020 @04:50AM (#25383994)
That's a pretty error prone way of writing SVGs though. In well written code you would use a strongly typed API and that API would be exactly the same for a binary format.

Think about how you write Protobuf files for example.

Re:CSS in GitHub Readmes by saagarjha on Friday December 11, 2020 @04:52AM (#25384013)
In the circumstances where I actually cared I would use a strongly typed language with nice wrappers, of course ;) The reason why I love SVGs is you can just belt them out from scripts and it's the easiest thing in the world. Same reason why I love GraphViz and Netpbm.
Re:CSS in GitHub Readmes by mldbk on Wednesday December 09, 2020 @08:08AM (#25358082)
SVG is vector. So basically XML is suitable for that task.
Re:CSS in GitHub Readmes by porphyra on Wednesday December 09, 2020 @01:04PM (#25361530)
One could conceivably make a binary format based on Messagepack or Flatbuffers for vector data, which would be much more efficient and eliminate rounding problems of converting between floats and decimal numbers in text representations.
Re:CSS in GitHub Readmes by chrismorgan on Tuesday December 08, 2020 @01:57PM (#25349805)
When you load an SVG file as an image, JavaScript is not executed, but SMIL animations and CSS (which includes animations) are.

If you open the SVG file directly, then JavaScript will be executed. But any hosting platforms that hosts your content on their domain should filter out any JavaScript on SVG as it would on HTML.

Re:CSS in GitHub Readmes by inetknght on Tuesday December 08, 2020 @02:13PM (#25349970)
> But any hosting platforms that hosts your content on their domain should filter out any JavaScript on SVG as it would on HTML.

That's definitely not a thing that happens. Web servers just serve the file as-is.

Re:CSS in GitHub Readmes by mormegil on Tuesday December 08, 2020 @02:18PM (#25350017)
The point is they either need to filter the served content, or serve it from a different domain (e.g. githubusercontent.com), otherwise you have XSS-like problems.
Re:CSS in GitHub Readmes by michaelmior on Tuesday December 08, 2020 @02:29PM (#25350152)
My understanding is that things like this are one of the reasons GitHub moved GitHub Pages subdomains from github.com to github.io.
Re:CSS in GitHub Readmes by felixfbecker on Tuesday December 08, 2020 @03:22PM (#25350820)
GitHub raw endpoints do it. They will either serve the SVG without an image/svg+xml Content-Type, making it not render in the browser, or you have to append ?sanitize=true to the URL which will, as the name suggest, sanitize it.
Re:CSS in GitHub Readmes by reflectiv on Wednesday December 09, 2020 @10:20PM (#25369240)
ok but that is github...parent poster stated its common to do that...it is not.
Re:CSS in GitHub Readmes by detaro on Wednesday December 09, 2020 @11:13PM (#25369617)
It's web security 101 for handling user uploads. (although in the case of SVG most sites solve it by just not accepting "weird" formats like SVG)
Re:CSS in GitHub Readmes by Kiro on Tuesday December 08, 2020 @02:43PM (#25350319)
Re:CSS in GitHub Readmes by guessmyname on Tuesday December 08, 2020 @01:47PM (#25349656)
Yes, that’s what I am thinking. I can imagine hundreds of security researchers writing a proof of concept to report this “feature” as a security problem to GitHub’s bug bounty program.
Re:CSS in GitHub Readmes by bamboleo on Tuesday December 08, 2020 @02:06PM (#25349892)
There’s nothing to report. For all intents and purposes SVG files are treated exactly like images. All interactivity and even the ability to load other resources is disabled.

FYI millions of readmes have had SVG badges for years.

Re:CSS in GitHub Readmes by fractionalhare on Tuesday December 08, 2020 @02:48PM (#25350390)
Pretty sure they're just making a joke that a lot of bug bounty programs get tons of bullshit reports from security "researchers" who don't understand what they're doing. They're not actually claiming there's a legitimate issue.
Re:CSS in GitHub Readmes by xml on Wednesday December 09, 2020 @01:27AM (#25355915)
There are SVGs which will crash most browsers, so SVGs could still be abused for denial-of-service attacks.

For example, you could post one of those SVGs in every issue thread of a GitHub project if you wanted to mess with someone.

Not eligible for a bug bounty though since this issue has been known (but not fixed) for years.

Re:CSS in GitHub Readmes by jancsika on Tuesday December 08, 2020 @04:30PM (#25351622)
I'm not sure that's true.

For example, what happens when you right-click "View image" on an svg file? Does embedded JS get run in that case?

Re:CSS in GitHub Readmes by throw_m239339 on Wednesday December 09, 2020 @01:29AM (#25355919)
> For example, what happens when you right-click "View image" on an svg file? Does embedded JS get run in that case?

Servers can use CSP http headers to disable javascript execution completely AFAIK. Obviously older browsers like IE that do not support CSP will be vulnerable, but at that point, IE should be simply banned by Webservers, for the sake of the user.

Re:CSS in GitHub Readmes by favorited on Tuesday December 08, 2020 @04:25PM (#25351560)
One version of the SVG standard had raw socket support, which thankfully was removed.

They basically wanted everything that Flash had.

Re:CSS in GitHub Readmes by frabjoused on Tuesday December 08, 2020 @01:53PM (#25349734)
I just tried this in a Github readme, it looks like Github removes the JS.

Would be interesting to try to find a hole in this.

Re:CSS in GitHub Readmes by bamboleo on Tuesday December 08, 2020 @02:02PM (#25349854)
There is no hole. The SVG is loaded as an image. If you find a hole, it would be in the browser’s handling of SVG images, which would be a pretty big hole.