Kuma: Magic is incorrectly using image/svg as MIME type for SVG files, preventing uploads of SVG files

Created on 14 Nov 2019  路  12Comments  路  Source: mdn/kuma

Magic or libmagic is incorrectly using image/svg as the MIME type for SVG uploads, rather than image/svg+xml, which is the only correct MIME type [1] (and the one we've always used in the past).

Normally, we keep SVG uploads disabled for security reasons since SVG can contain JavaScript code. However, we like to use it for diagrams and the like because they can be translated, and they are more efficient for that purpose in many cases. When we want to upload SVG, we go to the admin panel in Django and in the Constance panel, add "image/svg+xml" to the WIKI_ATTACHMENT_ALLOWED_TYPES string. Then we upload the file and restore the previous string to that preference.

This is no longer working; even with image/svg+xml listed in the preference, uploads fail with an error announcing that "Files of this type are not permitted." This should work, however.

This issue is blocking work on WebXR and potentially other documentation that requires the use of diagrams to explain things properly. Hopefully the fix is not complicated.

[1] https://www.iana.org/assignments/media-types/media-types.xhtml#image

p2

All 12 comments

Hey Sheppy, can you try image/svg instead? Looks like it's an issue in a library we are using.

Using image/svg allows uploading but then the resulting file is not recognized by CKEditor or web browsers as a valid image file and will not render. The library needs to be fixed.

@atopal ^

How about this for a solution:

1) If the computed mimetype is image/svg we override and say it's image/svg+xml.
2) If you're a superuser or staff and the mimetype is image/svg+xml we skip the validation check and just allow it.

That worked for me in a quick hack. Now I was able to insert my SVG:
Screen Shot 2019-11-20 at 2 51 41 PM

It's a bit convoluted but it certainly fixes the problem.

@escattone You looked into this but I see no comment from you. Perhaps you wrote your comment elsewhere.

That works for me. It will be better than the current situation by far.

There are 29 users with staff status.
If we go for this solution, I wouldn't mind removing the use of Constance and just switching to a plain environment variable for this.

@escattone If you don't mind it, I can take a stab.

@peterbe I had spent some time last week looking into getting libmagic to return image/svg+xml rather than image/svg, but I couldn't see how to resolve that. It seems like a configuration bug, but I'm not sure. I like your proposed workaround, so please go ahead and take a stab, thanks!

Peter, if you are working on this, do we need to remove something from the current sprint to accommodate that?

Peter, if you are working on this, do we need to remove something from the current sprint to accommodate that?

I'm ahead on my sprint stuff. Besides, this is easy to do.

Be sure to check to make sure the SVG also renders when the page is presented to the user, both on the wiki and on the react site. I could see that being handled differently in different code paths. :)

Eagerly waiting for this one. I am starting to pile up SVGs to add to pages. :)

Be sure to check to make sure the SVG also renders

Just to be clear; this is more of a note-to-self-and-other-writers, right?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tobinmori picture tobinmori  路  13Comments

peterbe picture peterbe  路  7Comments

atopal picture atopal  路  10Comments

Gregoor picture Gregoor  路  4Comments

peterbe picture peterbe  路  6Comments