Closed (duplicate)
Project:
Drupal core
Version:
main
Component:
filter.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
24 Feb 2017 at 10:48 UTC
Updated:
28 May 2026 at 09:11 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
neograph734I ran into this exact same problem when working on #2842780: Add a token for the site logo.
Since svg's are perfectly valid resources for a src attribute of an img element according to the HTML5 specification paragraph 4.7.1, naturally I'd suppose it should be supported by Drupal as well. (Though there are more issues ragarding svg files.)
I'd like to propose a third option; in addition to getimagesize(), also check if the file is a valid svg file. For instance by checking its MIME-type.
If fact, PHP does not even recommend using getimagesize to detect if a file is a valid image:
So we might want to get rid of that as well?
Comment #3
neograph734What about replacing
with
Though this might not accept certain extensions that getimagesize() did accept (swf, jpc, jpf, jb2 and swc), I think the acceptance of svg over those could be a valid trade off. (getimagesize() would accept all IMAGETYPE_XXX constants, where this method would only accept a part of them http://php.net/manual/en/function.image-type-to-mime-type.php)
Comment #5
neograph734I forgot the @ in case the file does not exist.
Comment #6
neograph734Hmm, it appears that some webservers configurations will recognize the files as
text/plainortext/htmlrather than theimage/svg+xmlI was aiming for. So this does not solve the problem...We'd probably need some other solution then...
Comment #7
neograph734So I have done some additional searching, this actually has been requested as a PHP feature; Request #71517 Implement SVG support for getimagesize() and friends, but it has not received a lot of attention yet so it probably won't happen soon...
Furthermore my suggestion from #3 to rely on MIME-types is not safe because finfo_open only checks for known patterns in files, which can be deliberately added, making the files appear as another MIME-type. (Perhaps that should be added as a comment above getimagesize()?)
And third, SVG files can contain JavaScript (MDN example). I suppose we'd want to sanitize or block that.
So, the best I could come up with would be something like this:
Where $custom_svg_schema could be an adapted version of the svg schema, which does not allow script tags and would cause the validation to fail.
Basically everything described in this StackOverflow post.
But I really have no experience with this...
Comment #8
karol haltenberger commentedI still think the filter should only check if the file is local and not bother with image formats and sizes.
Ensuring that it is an image should be the responsibility of whatever or whoever put the url there (plugin, widget, the person typing it in etc.).
Comment #11
amaisano commentedAny progress on this? Our authors can choose SVG files in the WYSIWYG editor, but when they preview or publish the page, they are seeing a red X icon due to this bug.
Comment #13
zolt_toth commentedIt is still an issue, with Drupal core 8.7.x.
Comment #16
neograph734There are two problems here.
At the bottom of the article is a link to an issue in Wordpress which attempts to solve this by using a huge whitelist: https://core.trac.wordpress.org/attachment/ticket/24251/24251.2.diff
UPDATE, after reading #2868079-14: Add a default Content-Security-Policy-header for svg files I understand that SVG's in HTML img tags should not pose a risk. That is great for this issue because the sanitizing process should not be a blocker then.
Comment #17
neograph734Comment #18
neograph734I think something like this could work.
Comment #19
neograph734And I think this should suffice as a test
Comment #21
neograph734Had a typo in classy :(
Switched to using the built in mime type guesser and also asserting that external SVG files are invalid.
Comment #23
neograph734Built on latest dev.
For lower version one can use
MimeTypeGuesser::guess()Instead.Comment #27
smustgrave commentedPatch fails to apply to 9.5
Comment #28
longwaveComment #29
smustgrave commentedRerolled
Comment #31
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #32
pierrepaul commentedComment #33
smustgrave commentedWill also need an issue summary update before review.
Comment #36
rpayanmPlease review.
Comment #37
smustgrave commentedThanks!
The issue summary still needs to be updated.
Comment #39
alisonI think this issue (#2855653) and #2998318: Allow local svg image with "Restrict images to this site" filter may be duplicates of each other.
Comment #42
idebr commentedI'll close this issue in favor of #2998318: Allow local svg image with "Restrict images to this site" filter so we can focus our efforts in the related issue