Problem

Page: admin/appearance/settings
Action: I want to set an svg image file as the logo

Situation 1:
- Place the file logo.svg myself on the root of the web site.
- Uncheck "Use the default logo supplied by the theme".
- Fill in logo.svg in "Path to custom logo".
- Click "Save configuration".

result: OK, logo changed and displays as expected. See Figure 1 which demonstrates this behavior.

Situation 2:
- Uncheck "Use the default logo supplied by the theme".
- Browse to the logo.svg on my local computer and select it in "Upload logo image".
- Click "Save configuration".

result: file refused with error messages:

    The specified file logo.svg could not be uploaded.
        - Image type not supported. Allowed types: png jpeg gif
        - Only files with the following extensions are allowed: jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp.
    The logo could not be uploaded.

What is wrong:
- The 1st error message comes from the active toolkit in the Image system, but as the logo will not be manipulated by the toolkit, it should stay out of this setting.
- The 2nd error is even stranger as the logo file now suddenly seems to be treated as a regular file upload.

See Figure 2 for error messages when uploading an SVG.

Proposed resolution

  • There should only be a check if the logo is a regular/known image format.
  • Both ways of defining the logo should react the same.

See Figure 3 for expected behavior when uploading an SVG.

User interface changes

Update error messages when uploading an invalid file.

Current (when uploading a .txt file):

The specified file logo.txt could not be uploaded.

    The image file is invalid or the image type is not allowed. Allowed types: png, jpeg, jpg, jpe, gif, webp

Expected:

The specified file logo.txt could not be uploaded.

    Only files with the following extensions are allowed: png gif jpg jpeg apng svg.

See Figure 4 for expected behavior when uploading an invalid file.

Remaining tasks

  • Decide if it's acceptable to mark "administer themes" as "restrict access: true" to gain the functionality of using SVG as the logo.
  • If not, decide how to sanitize SVG images - see comment 176 for details

API changes

None.

Contributor tasks needed
Task Novice task? Contributor instructions Complete?
Create a patch Instructions
Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards Instructions

Screenshots and mockups

Figure 1. Defining a custom logo path after uploading a file directly to the filesystem.

Figure 2. Current core behavior when attempting to upload an SVG.

Figure 3. Expected core behavior when attempting to upload an SVG.

Figure 4. Expected core behavior when attempting to upload an invalid file type.

CommentFileSizeAuthor
#179 2259567-179.patch3.28 KBjoegraduate
#173 drupal-n2259567-173.patch3.29 KBdamienmckenna
#173 drupal-n2259567-173.interdiff.txt477 bytesdamienmckenna
#168 2259567-168.patch2.82 KBgauravvvv
#167 2259567-nr-bot.txt151 bytesneeds-review-queue-bot
#165 Beforepatch.pdf192.86 KBrinku jacob 13
#165 Afterpatch.pdf182.79 KBrinku jacob 13
#160 2259567-160-9-3-x.patch2.91 KBjcnventura
#152 svg-restrict-fig4.png60.46 KBcaesius
#152 svg-restrict-fig3.png55.26 KBcaesius
#152 svg-restrict-fig2.png76.88 KBcaesius
#152 svg-restrict-fig1.png57.55 KBcaesius
#146 2259567-146-9-2-x.patch2.81 KBjoegraduate
#137 2259567-137--allow-svg-image-upload-d9-2-beta-3.patch2.92 KBtrackleft2
#134 2259567--134-allow-svg-image-upload-d9-2-x.patch3 KBjcnventura
#123 interdiff_121_123.txt717 bytesanmolgoyal74
#123 2259567--123-allow-svg-image-upload-d9-2-x.patch5.98 KBanmolgoyal74
#121 2259567--121-allow-svg-image-upload-d9-2-x.patch5.96 KBanmolgoyal74
#119 2259567--119-allow-svg-image-upload-d9-1-x.patch5.96 KBtrackleft2
#113 interdiff_112-113.txt890 bytesvacho
#113 2259567-113.patch6 KBvacho
#112 2259567-112.patch6.12 KBvacho
#107 2259567-107.patch5.94 KBandypost
#107 interdiff.txt744 bytesandypost
#105 2259567-105.patch5.95 KBandypost
#105 interdiff.txt4.34 KBandypost
#102 drupal-logo_formats-2259567-102-d8.patch5.79 KBa_khalipau
#98 interdiff-2259567-94-98.txt3.54 KBeelkeblok
#98 drupal-logo_formats-2259567-98-d8.patch5.7 KBeelkeblok
#97 drupal-logo_formats-2259567-tests_only-d8.patch2.17 KBeelkeblok
#94 drupal-logo_formats-2259567-94-d8.patch4.4 KBeelkeblok
#92 system-allow_svg_logo_upload-2259567-92-D8.patch3.15 KBhuzooka
#70 logo_formats-2259567-70.patch3.93 KBlobsterr
#68 After_patch.JPG408.08 KBTrupti Bhosale
#68 After_patch_1.JPG405.13 KBTrupti Bhosale
#68 Before_patch.JPG371.23 KBTrupti Bhosale
#60 Screen Shot 2015-11-16 at 4.20.13 PM.png441.59 KBmgifford
#59 logo_formats-2259567-59.patch3.41 KBlendude
#59 interdiff-2259567-56-59.txt798 byteslendude
#56 logo_formats-2259567-56.patch3.34 KBlendude
#56 interdiff-2259567-40-56.txt2.25 KBlendude
#40 logo_formats-2259567-40.patch2.43 KBnelp
#35 logo_formats-2259567-34.patch2.42 KBoriol_e9g
#32 logo_format-2259567-32.patch2.44 KBoriol_e9g
#27 Screen Shot 2015-05-15 at 6.04.24 PM.png238.63 KBgyuhyon
#27 Screen Shot 2015-05-15 at 6.04.59 PM.png232.09 KBgyuhyon
#24 unnecessary-2259567-24.patch2.29 KBnvahalik
#22 unnecessary-2259567-22.patch1.51 KBnvahalik
#19 files.png54.28 KBmanjit.singh
#16 unnecessary-2259567-15.patch719 bytesnvahalik

Issue fork drupal-2259567

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

sidharthap’s picture

Drupal supports GIF, JPG and PNG as Drupal 8 used GD2 image manipulation toolkit and GD2 does not supports SVG formats. May be in future Drupal will used ImageMagick.
Follow this links http://www.sitepoint.com/imagick-vs-gd/ for difference between imagick vs gd.
Here is a related issue reported https://drupal.org/node/238678.

Thanks
Sidhartha

fietserwin’s picture

You are right, but the point here is that a logo is not manipulated in any way by Drupal. So any restrictions due to the active toolkit, and the formats that it (does not) support, should not be applied to the logo, nor should any format restriction from somewhere in the file module be applied.

sidharthap’s picture

There is no restriction from file module. Even we pass the extensions to validate, it will get fail at the toolkit label while manipulating the image.

itapplication’s picture

Issue tags: +theme logo, +logo file format

I experience unnecessary restrictions on logo format for .svg only. I place logo.png in theme folder but {{logo}} print only logo.svg. Why?

ckrina’s picture

akalata’s picture

Issue tags: -theme logo, -logo file format

Removing unnecessary tags (per [#1023102]).

joelpittet’s picture

Issue tags: +svg, +Novice, +frontend

Tagging for sprint tomorrow and cross linking it as I ran across this while converting logo to be in a block.

joelpittet’s picture

Title: Unnecessary restrictions on logo format » Unnecessary restrictions on logo format: Can't upload replacement SVG logo
Issue tags: +mobile

Updating title.

joelpittet’s picture

Priority: Normal » Major

Discussed with @webchick and bumping to major.

mark.labrecque’s picture

Assigned: Unassigned » mark.labrecque
jmarkel’s picture

Issue summary: View changes
mark.labrecque’s picture

Thanks jmarkel! I will be working on this at the DrupalCon sprint tomorrow and will take these suggestions into account

nvahalik’s picture

I will be working on this at the DrupalConLA mentored sprint.

mark.labrecque’s picture

I have already begun work on this nvahalik. Would you like to work together on it?

mark.labrecque’s picture

Assigned: mark.labrecque » Unassigned
nvahalik’s picture

Status: Active » Needs review
StatusFileSize
new719 bytes

The logo file upload form validator now uses the same file validator as the favicon (minus the .ico extension).

mark.labrecque’s picture

I reviewed this and verified that the patch allowed an SVG file to be uploaded to global theme settings. I will wait on testbot and then RTBC.

mark.labrecque’s picture

Status: Needs review » Reviewed & tested by the community
manjit.singh’s picture

StatusFileSize
new54.28 KB

manually test patch .. working fine.. Attaching screenshot

fietserwin’s picture

Status: Reviewed & tested by the community » Needs work

Thanks for picking this up.

Regarding the patch:

+++ b/core/modules/system/src/Form/ThemeSettingsForm.php
@@ -364,7 +364,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
-      $validators = array('file_validate_is_image' => array());
+      $validators = array('file_validate_extensions' => array('png gif jpg jpeg apng svg'));
 

- According to http://en.wikipedia.org/wiki/Comparison_of_web_browsers#Image_format_sup... we'd better support bmp instead of apng...
- I miss webp, not widely supported yet, but it seems to be coming (during the lifetime of D8).
- This was the only (non-test) use of function file_validate_is_image(), so should we deprecate or even just remove this function?

Regarding how the patch compares to the proposed solution:

This patch solves the 1st point, but does not solve the other 2 points. Dropping the 2nd point is OK for me, but the 3rd point, the help text, remains obscure to me: Examples: logo.svg (for a file in the public file system), public://logo.svg, or core/themes/bartik/logo.svg.. You have to read and interpret very carefully to realize that logo.svg may also point to the root of the Drupal installation (and, absolutely not clear or even deductible, in its current implementation gets precedence over the public:// directory).

So, we should either change the scope of the patch (include point 3) or change the scope of this issue by creating a follow up issue (not my preference as changing help texts used to be a no-go during the lifetime of a major release).

manjit.singh’s picture

Adding bmp extension would not be a bad idea.. If its possible !! lets wait for some reviews on #20.

nvahalik’s picture

Status: Needs work » Needs review
StatusFileSize
new1.51 KB

@fietserwin,

I've added the bmp extension since it was valid and wouldn't be anymore.

Regarding #2, both the logo and the favicon work exactly the same now, so I'm inclined to just leave it be.

#3 - updated in the patch.

Examples: core/themes/seven/logo.svg (for a file in the document root) or public://logo.svg for a file in the public files directory.

Status: Needs review » Needs work

The last submitted patch, 22: unnecessary-2259567-22.patch, failed testing.

nvahalik’s picture

Status: Needs work » Needs review
StatusFileSize
new2.29 KB

Updated the test.

lauriii’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

I think we have to add tests for this cause this is considered as bug.

lauriii’s picture

Issue tags: +Needs manual testing
gyuhyon’s picture

uploading SVG files to logo and favicon is working

but uploading BMP file to logo nor favicon is not working as below screenshots.

gyuhyon’s picture

Issue tags: -Needs manual testing

no manual test needed

fietserwin’s picture

- bmp was not added to the list.
- I'm not sure about the need of testing each and every format. Just testing 1 accepted format and 1 not-accepted format seems enough coverage to me.
- The help text is still wrong: when you enter logo.svg, both /logo.svg and public://logo.svg are tried (in that order) and accepted if found. Nice feature but extremely difficult to describe correctly :(
- It was not that logo and icon behaved differently, but that uploading versus manually entering a file on the server behave differently. But I propose to leave it as is,so admin/editors/themers can circumvent the "arbitrary" limitation to certain image formats. If we decide to leave as is, the issue summary should be updated by removing that point.

nvahalik’s picture

Sorry about the BMP not being added to the list. That was my mistake! I'll upload another patch after we get the message straightened out because it's super tedious trying to fix the tests for every message change.

Here are some further options for the description text:

Examples: test.png will look for /logo.png and sites/drupal.dd/files/test.png. Using public://test.png will use an image located at sites/drupal.dd/files/test.png.

Enter a path to an image. Entering test.png will look for /logo.png and sites/drupal.dd/files/test.png. Using public:// before a path (e.g. public://test.png) will use explicitly use an image that has been uploaded to Drupal's public file directory such as sites/drupal.dd/files/test.png.

fietserwin’s picture

Or something like:

Enter a path to an image. Drupal will look for the file relative to the Drupal root or the public file system. Explicitly using public:// before the path will only look in the public file system ({actual value of public}).

oriol_e9g’s picture

Status: Needs work » Needs review
StatusFileSize
new2.44 KB

Maybe it's a little verbose but I'll try with this.

oriol_e9g’s picture

Priority: Major » Normal

This is not major.

Status: Needs review » Needs work

The last submitted patch, 32: logo_format-2259567-32.patch, failed testing.

oriol_e9g’s picture

Status: Needs work » Needs review
StatusFileSize
new2.42 KB
oriol_e9g’s picture

Status: Needs review » Needs work

The last submitted patch, 35: logo_formats-2259567-34.patch, failed testing.

andypost’s picture

Issue tags: +dcuacs2015

You should change a render (and CSS) to properly display SVG

http://stackoverflow.com/questions/4476526/do-i-use-img-object-or-embed-...

nelp’s picture

Looking at this issue her at DrupalCon Barcelone

nelp’s picture

Status: Needs work » Needs review
Issue tags: +Barcelona2015
StatusFileSize
new2.43 KB

Rerolled patch from #34. The patch needs review.

Status: Needs review » Needs work

The last submitted patch, 40: logo_formats-2259567-40.patch, failed testing.

andypost’s picture

Issue tags: +Needs manual testing

I'm pretty sure that uploading svg file will not display logo properly, because it's not image to render with IMG tag

+++ b/core/modules/system/src/Form/ThemeSettingsForm.php
@@ -361,7 +361,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
-      $validators = array('file_validate_is_image' => array());
+      $validators = array('file_validate_extensions' => array('bmp png gif jpg jpeg apng svg'));

svg is not image

valthebald’s picture

@andypost: if I upload an svg file to sites/default/files thru the file system, and enter path in the theme settings, it is working. So no, SVG files are displayed as images correctly (in all supported browsers)

nelp’s picture

God point. But according to http://caniuse.com/#feat=svg-img the use of svg in a img tag is widely supportet.

The last submitted patch, 24: unnecessary-2259567-24.patch, failed testing.

duaelfr’s picture

I'm mentoring @nelp, @FMB and @fabio84 on that issue at DrupalCon Barcelona.
The patch has been rerolled and manually tested but automated tests are failing so they are currently working on fixin that tests.

fabio84’s picture

Patch #40 works for me, we have to figure out why some tests on https://www.drupal.org/pift-ci-job/39647 fails

fmb’s picture

  • So it turns out this patch introduces a bug in the tests. We are running them locally to determine what happens.
  • Should we really support apng and bmp?
  • I think the description is still confusing and could be improved, plus it needs a full stop.
fabio84’s picture

I tested Drupal\system\Tests\System\ThemeTest and I got 15 errors with the patch and 5 errors without the patch

fabio84’s picture

errors with patch:

Value 'public://' is equal to value 'sites/simpletest/763970/files/image-test.png'.	Other	ThemeTest.php	122	Drupal\system\Tests\System\ThemeTest->testThemeSettings()	Fail
Value 'sites/simpletest/763970/files/image-test.png' is equal to value 'public://image-test.png'.	Other	ThemeTest.php	123	Drupal\system\Tests\System\ThemeTest->testThemeSettings()	Fail
Value 'http://localhost:8080/drupal/sites/simpletest/763970/files/image-test.png.pagespeed.ce.HKO7tjhvkE.png' is equal to value 'http://localhost:8080/drupal/sites/simpletest/763970/files/image-test.png'.	Other	ThemeTest.php	133	Drupal\system\Tests\System\ThemeTest->testThemeSettings()	Fail
Value 'public://' is equal to value 'sites/simpletest/763970/files/image-test.png'.	Other	ThemeTest.php	122	Drupal\system\Tests\System\ThemeTest->testThemeSettings()	Fail
Value 'sites/simpletest/763970/files/image-test.png' is equal to value 'public://image-test.png'.	Other	ThemeTest.php	123	Drupal\system\Tests\System\ThemeTest->testThemeSettings()	Fail
Value 'http://localhost:8080/drupal/sites/simpletest/763970/files/image-test.png.pagespeed.ce.HKO7tjhvkE.png' is equal to value 'http://localhost:8080/drupal/sites/simpletest/763970/files/image-test.png'.	Other	ThemeTest.php	133	Drupal\system\Tests\System\ThemeTest->testThemeSettings()	Fail
Value 'public://' is equal to value 'core/themes/classy/logo.svg'.	Other	ThemeTest.php	122	Drupal\system\Tests\System\ThemeTest->testThemeSettings()	Fail
Value 'core/themes/classy/logo.svg' is equal to value 'public://logo.svg'.	Other	ThemeTest.php	123	Drupal\system\Tests\System\ThemeTest->testThemeSettings()	Fail
Value 'http://localhost:8080/drupal/sites/simpletest/763970/files/image-test.png.pagespeed.ce.HKO7tjhvkE.png' is equal to value 'http://localhost:8080/drupal/sites/simpletest/763970/files/image-test.png'.	Other	ThemeTest.php	133	Drupal\system\Tests\System\ThemeTest->testThemeSettings()	Fail
Value 'public://' is equal to value 'core/themes/classy/logo.svg'.	Other	ThemeTest.php	122	Drupal\system\Tests\System\ThemeTest->testThemeSettings()	Fail
Value 'core/themes/classy/logo.svg' is equal to value 'public://logo.svg'.	Other	ThemeTest.php	123	Drupal\system\Tests\System\ThemeTest->testThemeSettings()	Fail
Value 'http://localhost:8080/drupal/core/misc/druplicon.png.pagespeed.ce.4OO_nQPwIR.png' is equal to value 'http://localhost:8080/drupal/core/misc/druplicon.png'.	Other	ThemeTest.php	133	Drupal\system\Tests\System\ThemeTest->testThemeSettings()	Fail
Value 'public://' is equal to value 'core/themes/classy/logo.svg'.	Other	ThemeTest.php	122	Drupal\system\Tests\System\ThemeTest->testThemeSettings()	Fail
Value 'core/themes/classy/logo.svg' is equal to value 'public://logo.svg'.	Other	ThemeTest.php	123	Drupal\system\Tests\System\ThemeTest->testThemeSettings()	Fail
Value SimpleXMLElement::__set_state(array( 0 => 'http://localhost:8080/drupal/sites/simpletest/763970/files/image-test_0.png.pagespeed.ce.HKO7tjhvkE.png', )) is equal to value 'http://localhost:8080/drupal/sites/simpletest/763970/files/image-test_0.png'.	Other	ThemeTest.php	185	Drupal\system\Tests\System\ThemeTest->testThemeSettings()	Fail

errors without patch:

Value 'http://localhost:8080/drupal/sites/simpletest/352600/files/image-test.png.pagespeed.ce.HKO7tjhvkE.png' is equal to value 'http://localhost:8080/drupal/sites/simpletest/352600/files/image-test.png'.	Other	ThemeTest.php	134	Drupal\system\Tests\System\ThemeTest->testThemeSettings()	Fail
Value 'http://localhost:8080/drupal/sites/simpletest/352600/files/image-test.png.pagespeed.ce.HKO7tjhvkE.png' is equal to value 'http://localhost:8080/drupal/sites/simpletest/352600/files/image-test.png'.	Other	ThemeTest.php	134	Drupal\system\Tests\System\ThemeTest->testThemeSettings()	Fail
Value 'http://localhost:8080/drupal/sites/simpletest/352600/files/image-test.png.pagespeed.ce.HKO7tjhvkE.png' is equal to value 'http://localhost:8080/drupal/sites/simpletest/352600/files/image-test.png'.	Other	ThemeTest.php	134	Drupal\system\Tests\System\ThemeTest->testThemeSettings()	Fail
Value 'http://localhost:8080/drupal/core/misc/druplicon.png.pagespeed.ce.4OO_nQPwIR.png' is equal to value 'http://localhost:8080/drupal/core/misc/druplicon.png'.	Other	ThemeTest.php	134	Drupal\system\Tests\System\ThemeTest->testThemeSettings()	Fail
Value SimpleXMLElement::__set_state(array( 0 => 'http://localhost:8080/drupal/sites/simpletest/352600/files/image-test_0.png.pagespeed.ce.HKO7tjhvkE.png', )) is equal to value 'http://localhost:8080/drupal/sites/simpletest/352600/files/image-test_0.png'.	Other	ThemeTest.php	186	Drupal\system\Tests\System\ThemeTest->testThemeSettings()	Fail

Maybe the 5 errors I get also without patch are caused by Google Chrome and PageSpeed?

nelp’s picture

We think there is some errors in the test. We have to run the tests in a new installation. The sprint here in Barcelona is closing now, but I will continue working on the issue in next week. All input are welcome.

Regarding the problems in the description belongs in its own issue?

fabio84’s picture

I got the same 5 errors on FireFox

The last submitted patch, 40: logo_formats-2259567-40.patch, failed testing.

lendude’s picture

StatusFileSize
new2.25 KB
new3.34 KB

Bit of a clean-up

lendude’s picture

Status: Needs work » Needs review

Bit of a clean-up

Status: Needs review » Needs work

The last submitted patch, 56: logo_formats-2259567-56.patch, failed testing.

lendude’s picture

Status: Needs work » Needs review
StatusFileSize
new798 bytes
new3.41 KB

duh, this should be better...

mgifford’s picture

Issue summary: View changes
StatusFileSize
new441.59 KB

That seems to work just fine. Support for http://caniuse.com/#search=apng seems pretty weak.

Didn't seem like there was consensus around that. Patch seems fairly straight forward.

Screenshot with uploaded SVG image.

joelpittet’s picture

Issue tags: -Needs manual testing

@Lendude does the tests test for SVG explicitly?

lendude’s picture

@joelpittet in #59, the only thing getting tested is the description string. I was only trying to get the current patch in the green. Really haven't looked into testing file uploads.

joelpittet’s picture

Really wish I knew what that implicit public file is all about. I'm guessing it was needed to be removed for this to work for some reason?

The only thing that looks like it would be totally needed is the validators change... that is just from reading the code (didn't test)

lendude’s picture

@joelpittet from the issue summary:

The help text on the field 'Path to custom log', "Examples: logo.png (for a file in the public filesystem), public://logo.png, or core/themes/seven/logo.png." should be rephrased as well, as a plain logo.png refers to the root of the web site, not the public file system

joelpittet’s picture

So to paraphrase you are are saying that implicit file path was pointing at webroot and that was just not useful?

Just guessing

lendude’s picture

I have no idea who put that in the issue summary, but that seems to be the reason the description change is in the patch. But I can totally get behind the argument that that is an unrelated change to this issue.

joelpittet’s picture

+++ b/core/modules/system/src/Form/ThemeSettingsForm.php
@@ -358,7 +357,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
-      $validators = array('file_validate_is_image' => array());
+      $validators = array('file_validate_extensions' => array('bmp png gif jpg jpeg apng svg'));

This may be the only line necessary to fix this issue. Maybe we can move the other changes to a follow-up if you agree?

And we can improve this line I think so we don't regress by hardcoding the image extensions we can aquire them the way the file_validate_is_image does:

    $image_factory = \Drupal::service('image.factory');
    $supported_extensions = $image_factory->getSupportedExtensions();
    $supported_extensions[] = 'svg';
    $validators = ['file_validate_extensions' => [implode(' ', $supported_extensions)]];
Trupti Bhosale’s picture

StatusFileSize
new371.23 KB
new405.13 KB
new408.08 KB

Tested the patch in #59 manually and it is working fine.
Observations
1.Gave the custom logo path in "Path to custom logo" field and clicked on Save Configuration button, success message is displayed and the logo is displayed correctly (tried with SVG and PNG image)
2.Uploaded a image in "Upload logo image" and clicked on Save Configuration button,success message is displayed and the logo is displayed as expected (tried with image with SVG and PNG format)
Attaching snapshot for reference.

lobsterr’s picture

Assigned: Unassigned » lobsterr
lobsterr’s picture

Assigned: lobsterr » Unassigned
StatusFileSize
new3.93 KB

I have added the changes from comment 67.

lendude’s picture

Status: Needs review » Needs work
+++ b/core/modules/system/src/Form/ThemeSettingsForm.php
@@ -358,7 +357,10 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
+      $supported_extensions = $image_factory->getSupportedExtensions();

Using this is a nice idea but currently only returns 'jpg', 'png' and 'gif' at the moment, so we would need to add more extensions then just 'svg'.

+++ b/core/modules/system/src/Form/ThemeSettingsForm.php
@@ -374,8 +376,6 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
-      $validators = array('file_validate_extensions' => array('ico png gif jpg jpeg apng svg'));

Making both fields use the same validators only works if we add the 'ico' extension.

I also think some text to show that there is a restriction on the type of files that you can upload would be good.

lauriii’s picture

+++ b/core/modules/system/src/Form/ThemeSettingsForm.php
@@ -358,7 +357,10 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
+      $supported_extensions = $image_factory->getSupportedExtensions();
+      $supported_extensions[] = 'svg';

why image factory cannot contain all these image types?

lendude’s picture

@lauriii According to comment #1 due to the use of the GD2 image manipulation toolkit and it only supporting those types. Don't know if that information is still current (but it seems to be).

mondrake’s picture

#72, #73:

yes, the ImageFactory just returns the extensions supported by the toolkit set as default.

Currently the GD toolkit returns 'png gif jpeg' (but see #2477381: GDToolkit::getSupportedExtensions returns incomplete list), and it's unlikely GD will support SVG which is a vector image format any soon. ImageMagick, currently in alpha for D8, can be configured to support more image formats, including SVG.

+++ b/core/modules/system/src/Form/ThemeSettingsForm.php
@@ -358,7 +357,10 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
+      $image_factory = \Drupal::service('image.factory');
+      $supported_extensions = $image_factory->getSupportedExtensions();
+      $supported_extensions[] = 'svg';

This would add a duplicate supported extension if svg is already returned by ImageFactory. You'd better merge the values instead.

In general, note that the use of Image objects kind of hints at the fact that you need to manipulate the source image (scale, resize, etc.), and the toolkit just needs to be able to process the image format. If you do not need to do this, but just upload a file and render the image from it, then you probably do not need to get to this - the list of extensions like in #59 would just do.

andypost’s picture

@mondrake good points, there's another great issue #2284577: Make image effects smarter, image toolkit operations dumber

andypost’s picture

Another idea is re-use effects for logo/favicon, would be great to have this issue for 8.1
logo is in "site branding" block so could have image style selection

valthebald’s picture

Issue tags: -Novice

Doesn't look Novice anymore

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

Version: 8.1.x-dev » 8.2.x-dev
drugan’s picture

More than two years are gone after the issue opening but the bug is still there. I've tested #70 patch and it works great but the question is why it is not commited so far? As I think the reasons are following:

1. The current GD library does not handle .svg images so just allowing to upload these images for a site logo does not automatically resolve the issue of displaying them.

2. Images with .svg extension may have different forms despite looking like **the same**. To see the differences just open those images taken from different resources in a text editor. For example, some of them may be affected by CSS properties (fill, width, height, ...), some can change these properties only in the image code, despite being successfully displayed on a page. Consequently, only a theme author knows what kind .svg they will accept and how they will process them.

If we agree that this issue is not the Drupal core's one then we need a solution on a theme level without touching the core.

Create theme-settings.php file in a theme root folder If you don't have one yet and copy/paste this into the file:


/**
 * @file
 * Provides an additional config form for theme settings.
 */

use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_form_system_theme_settings_alter().
 *
 * Form override for theme settings.
 */
function MYTHEME_form_system_theme_settings_alter(array &$form, FormStateInterface $form_state) {
  $form['#validate'][] = 'MYTHEME_form_system_theme_settings_validate';
}

function MYTHEME_form_system_theme_settings_validate(array &$form, FormStateInterface $form_state) {
  if (function_exists('file_save_upload')) {
       // Handle file uploads.
    $image_factory = \Drupal::service('image.factory');
    $supported_extensions = $image_factory->getSupportedExtensions();
    $supported_extensions[] = 'svg';
    $validators = ['file_validate_extensions' => [implode(' ', $supported_extensions)]];

    // Check for a new uploaded logo.
    $file = file_save_upload('logo_upload', $validators, FALSE, 0);
    if (isset($file)) {
      // File upload was attempted.
      if ($file) {
        // Put the temporary file in form_values so we can save it on submit.
        $form_state->setValue('logo_upload', $file);
      }
      else {
        // File upload failed.
        $form_state->setErrorByName('logo_upload', t('The logo could not be uploaded.'));
      }
    }
  }
}

Of course, you need to replace MYTHEME in the code with your theme name.

Some may ask why not declare the core's new HOOK__form_system_theme_settings_validate() and then just implement it on a theme. I think that this is redundant because some months later the core may implement ImageMagick library instead of current GD and therefore allow .svg extension, so the hook will deprecate and require to be deleted.

Thanks @LOBsTerr for the $validators definition snippet.

fietserwin’s picture

IMO, the site logo is not an image to be processed with the toolkit, so any restrictions coming forth of the active toolkit are out of place.

cri2mars’s picture

hi,
still the same format restriction in my 8.2.5
unable to upload a logo.svg from the public system...
in the global theme parameter, as in my pixture reloaded theme:

     Message d'erreur

    Le fichier spécifié logo.svg n'a pas pu être transféré.
        Type d'image non supporté. Types autorisés : png jpeg jpg jpe gif
        Seuls les fichiers se terminant par les extensions suivantes sont autorisés : jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp.
    Le logo n'a pas pu être téléchargé sur le serveur.

beside:

 // File upload failed.
          $form_state->setErrorByName('logo_upload', $this->t('The logo could not be uploaded.'));
        }
      }

      $validators = array('file_validate_extensions' => array('ico png gif jpg jpeg apng <strong>svg</strong>'));

i had to choose a .png format instead

joelpittet’s picture

To try to push this in a direction I'm going to ask for product manager review, since it effects the UI.
https://www.drupal.org/governance/core#product-manager

I agree with @fietserwin and would like to remove the toolkit half/feature in favour of SVG.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

yoroy’s picture

So the idea is to allow uploading an SVG file for the logo and then there are no problems? I can agree with that :)

Looks like the proposed fix is to make it so that the file uploaded as the site logo can not be interfered with by the imaging toolkit. That makes sense to me. Logos are often subject to strict rules on how to display them and how they should *not* be modified. So it seems ok to me to make the logo upload not available to the toolkit.

Does that help?

dunebl’s picture

Here is the result after applying this path (#70) on 8.3-dev:

patching file core/modules/system/src/Form/ThemeSettingsForm.php
Hunk #1 FAILED at 284.
Hunk #2 FAILED at 358.
Hunk #3 FAILED at 374.
3 out of 3 hunks FAILED -- saving rejects to file core/modules/system/src/Form/ThemeSettingsForm.php.rej
patching file core/modules/system/src/Tests/System/ThemeTest.php
Hunk #1 succeeded at 98 with fuzz 2 (offset -5 lines).
Hunk #2 succeeded at 111 (offset -5 lines).
holyfire’s picture

This is an issue that desperately looks like it's in need of leadership.

  • Why hasn't this issue been assigned to anyone to manage?
  • I really appreciate the theme level workaround in #81.
  • Why hasn't Product stepped in here... and/or any other input?

I'm definitely willing to help with testing on this one.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

xmacinfo’s picture

Version: 8.4.x-dev » 8.5.x-dev

There might be security issues with SVG files, but then again, the website owner should be able to use SVG files for site logos.

Bumping to 8.5.x.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

huzooka’s picture

Status: Needs work » Needs review
StatusFileSize
new3.15 KB

Hi here,

Please ignore this file (I haven't read the whole thread), I just need a raw patch which adds svg logo upload support.

eelkeblok’s picture

I'm looking into getting this going again, because it is rather ridiculous Drupal does not accept SVG logo uploads in 2018. To save others maybe some detective work, the main reason #70 is not applying anymore (the last patch that tries to address all issues from the summary) is actually two issues; #2954884: Cannot save theme settings form for themes without logo or favicon features and #2482783: File upload errors not set or shown correctly. Actually, while tracking down the changes breaking the patch, it actually looks like uploading SVGs may have worked at some point, because SVG was part of the allowed file extensions. However, at some point the validation was switched to file_validate_is_image, after which I expect it broke again.

I'll try and get a patch going again.

eelkeblok’s picture

StatusFileSize
new4.4 KB

This is effectively a reroll of #70. I have not touched tests for now, and I've had to move around some stuff due to mainly #2482783: File upload errors not set or shown correctly. Note that for this patch to apply to 8.5.3 you will also need the patch for #2954884: Cannot save theme settings form for themes without logo or favicon features.

eelkeblok’s picture

Considering it looks like SVG support was actually briefly available somewhere between Drupal 8.0 and 8.5, I think it is a good idea to try and test for that.

eelkeblok’s picture

Assigned: Unassigned » eelkeblok
eelkeblok’s picture

Here's a patch that adds an svg upload test. This is expected to fail as it does not contain the actual fix (which I will upload shortly). This does not include the changes to the test to cater for the change in error message, that didn't seem "fair" :)

eelkeblok’s picture

Here's some updates to the patch, including the above test. I changed the determining of the supported file extensions back to hardcoded, because I don't think it makes a ton of sense to involve supported file formats for the image toolkit, as the logo is not passed through it.

eelkeblok’s picture

Assigned: eelkeblok » Unassigned
Status: Needs work » Needs review

The last submitted patch, 97: drupal-logo_formats-2259567-tests_only-d8.patch, failed testing. View results

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

a_khalipau’s picture

StatusFileSize
new5.79 KB

Ported the patch from #98 to 8.7.x

Status: Needs review » Needs work

The last submitted patch, 102: drupal-logo_formats-2259567-102-d8.patch, failed testing. View results

nishat ahmad’s picture

core/modules/system/src/Form/ThemeSettingsForm.php
public function buildForm(array $form, FormStateInterface $form_state, $theme = '')
Line 213 use this code

 $form['logo']['settings']['logo_upload'] = [
        '#type' => 'file',
        '#title' => t('Upload logo image'),
        '#maxlength' => 40,
        '#description' => t("If you don't have direct file access to the server, use this field to upload your logo."),
        '#upload_validators' => [
         //'file_validate_is_image' => [],
	   'file_validate_extensions' => [
            'png gif jpg jpeg apng svg',
          ],
        ],
      ];
andypost’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new4.34 KB
new5.95 KB

New patch

- fix broken test
- changed code lines should not use deprecated calls
- no reason to place branding block in loop cos xpath() & test using first one only

tests are extended to test image & svg

The question - to we need to test exact reworded description?

Status: Needs review » Needs work

The last submitted patch, 105: 2259567-105.patch, failed testing. View results

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new744 bytes
new5.94 KB

Revert deprecated constructFieldXpath cos there's no alternative for a while

eelkeblok’s picture

The question - to we need to test exact reworded description?

We are not yet, right? I think it would make sense to test for the file types mentioned in the description. The exact wording makes less sense, but would be fine too, I guess.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

john cook’s picture

Status: Needs review » Needs work
Issue tags: +Needs security review, +Needs reroll

The patch does not apply, so this will need a reroll.

There may by security issues by allowing this as SVGs can contain javascript so the security may need to look at this to check if it could be accepted.

vacho’s picture

Issue tags: -Needs reroll
StatusFileSize
new6.12 KB

Patch rerolled :-)

vacho’s picture

StatusFileSize
new6 KB
new890 bytes

Solving test problems.

jungle’s picture

Status: Needs work » Needs review

#111: There may by security issues by allowing this as SVGs can contain javascript so the security may need to look at this to check if it could be accepted.

According to here https://developer.mozilla.org/en-US/docs/Web/SVG/SVG_as_an_Image#Restric...

For security purposes, Gecko places some restrictions on SVG content when it's being used as an image:

It seems that SVG as an Image is safe in Firefox at least.

Meanwhile, there is a rerolled patch, so I change the status to needs review.

matt_paz’s picture

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

trackleft2’s picture

Rerolled patch for 9.1

xmacinfo’s picture

Status: Needs review » Needs work
anmolgoyal74’s picture

Status: Needs work » Needs review
StatusFileSize
new5.96 KB

Re-rolled for 9.2.x

Status: Needs review » Needs work

The last submitted patch, 121: 2259567--121-allow-svg-image-upload-d9-2-x.patch, failed testing. View results

anmolgoyal74’s picture

Fixed the failing tests.

anmolgoyal74’s picture

Status: Needs work » Needs review
jcnventura’s picture

Issue summary: View changes
Status: Needs review » Needs work

I don't understand what all the fuss is about in this issue regarding the description. There's a reason why the 'description error' hasn't been addressed before: the description as it is is perfectly right.. Setting the path to 'logo.png' will not refer to a file in the site root, it refers to a file in the public filesystem. I've tested this in numerous instances just now.

Please rework the patch to address exclusively the SVG change, and remove the description changes, please.

Even if for some legacy reason the site root is also an applicable location, I don't think that documenting that behavior should be done in this issue. We should probably discuss if that is a behavior that should be kept (and documented) or removed entirely. And that kind of discussion is very off-topic from allowing a logo.svg file to be uploaded.

eelkeblok’s picture

Absolutely agreed. I never really got into the reasoning behind that change, but it was already being discussed 5 years ago and looks like concencus was already reached in ~#66. I think this may be the worst issue lifetime vs. lines of code changed ever :)

eelkeblok’s picture

Status: Needs work » Needs review
xmacinfo’s picture

Status: Needs review » Needs work

Last MR is incomplete and won't be committed without tests.

jcnventura’s picture

Status: Needs work » Needs review

Added back the tests that were removed between #123 and #127.

xmacinfo’s picture

Status: Needs review » Needs work
eelkeblok’s picture

Hm. How strange... I distinctly recall working on those tests. Must have made a mistake.

eelkeblok’s picture

The tests needed some adjusting too because of the revert of the description. Redid the failed merge and merged that back into the MR... 🤞

jcnventura’s picture

Status: Needs work » Needs review
StatusFileSize
new3 KB

I think I ruined the GitLab MR when I tried to understand why the tests were failing and couldn't understand why there were so many changes.

jcnventura’s picture

I've rebased the MR to the latest Drupal 9.2.x branch status. That should fix the problem.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

trackleft2’s picture

StatusFileSize
new2.92 KB

New patch for Drupal 9.2-beta3

Status: Needs review » Needs work
jcnventura’s picture

@trackleft2, can you try updating the MR in the gitlab issue? It's easier to understand the changes between your changes in #137 and my commit in #136.

jcnventura’s picture

@trackleft2, can you provide an interdifff between #137 and the MR in #135, please?

jcnventura’s picture

Sorry about the 15:55 re-roll. I rebased on 9.3.x and got all the core changes between 9.2.x and 9.3.x as part of the MR.

The 16:03 re-roll is against 9.2.x. Which doesn't make much sense, but at least the MR is a lot saner.

jcnventura’s picture

Status: Needs work » Needs review

joegraduate made their first commit to this issue’s fork.

joegraduate’s picture

Apologies for all of the commits/noise from the MRs. I couldn't figure out how to change the destination branch of the existing MR so I ended up creating a new one that is rebased on the latest 9.3.x branch (and includes the recent changes made to core/modules/system/tests/src/Functional/System/ThemeTest.php for #3220255: Convert assertions involving use of xpath on links to WebAssert).

joegraduate’s picture

StatusFileSize
new2.81 KB

Adding composer patch version of #144 for 9.2.x.

trackleft2’s picture

To summarize, the main issue surrounding this patch has to do with the way image validation is done(looks at the selected toolkit for the site, and finds file extensions that are compatible with it), and the fact that you can only use one image toolkit per site, which I've found to be limiting even without SVG.

To fix we could consider a more robust image toolkit options ecosystem.

Step 1 Make image toolkit a per image style setting since that is typically where the processing is done(Does not account for process on upload contrib modules, or settings), or per field setting, or a per file extension setting, and not a per site setting.
Step 2 Allow multiple toolkits
Step 3 Validate against all toolkits
Step 4 Allow processing of uploaded logo images with a toolkit, ha.

Or we could ask the Drupal core team: Theme logo images aren't even processed using an image toolkit, so why are we constraining extensions to a specific toolkit?

If this patch is applied to core before the next release, we could still go back and do all the things laid out in the 4 steps above, since really the only thing that is happening in the patch is a validator swap.

caesius’s picture

Status: Needs review » Reviewed & tested by the community

This patch works well considering the scope of the original issue, so RTBC from me.

I should, however, point out something I discovered while testing this. This patch does not check that an uploaded "image file" is actually an image; any arbitrary file can be uploaded as long as it has the correct file extension. This arguably could be considered a regression from core, where if you attempt to upload Text File.jpg as the site logo you will see the following error:

The specified file Text File.jpg could not be uploaded.

    The image file is invalid or the image type is not allowed. Allowed types: png, jpeg, jpg, jpe, gif, webp

I did some research to determine whether this should be considered a security issue and came across #2829048 and #2388749. The tl;dr for these is that the way Drupal core currently works is that if you upload a file with a specific extension it will serve it with the MIME type of that extension. There was a point during the development of Drupal 8.0 that a "mime guesser" was implemented, but it was reverted due to security concerns (see #41 on 2388749).

Additionally, I was able to reproduce this on a File media type by renaming a .jpg file to a .docx and Drupal allowed me to upload it, so this is not something that is limited to the theme logo field. Addressing this should be done with more generalized development in Drupal core in one of the two linked issues.

The suggestions outlined in #147 regarding handling of image toolkits and image files are also outside the scope of this issue and should be split off into new issues.

joegraduate’s picture

Rebased MR onto latest 9.3.x branch.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update

Sorry folks, the Issue Summary needs a bit of work, points below, and adding tag

  1. The before and after user interface text change should be in the section 'user interface changes'.
  2. Needs up to date screenshots in the IS. AFAICT the screenshots are 6 years old. They also need some text to explain which each screen shot is.
caesius’s picture

StatusFileSize
new57.55 KB
new76.88 KB
new55.26 KB
new60.46 KB

Uploading screenshots for use in the IS.

caesius’s picture

Issue summary: View changes
caesius’s picture

The issue summary has been updated per @quietone's suggestions.

One thing I noticed is that some file extensions, jpe and webp are now no longer allowed. Should we be including those file types or is that just a list of file formats the image toolkit supports (rather than necessarily a Drupal core-supported list)? The last mention of "webp" in this issue was 7 years ago in #20:

- I miss webp, not widely supported yet, but it seems to be coming (during the lifetime of D8).

caesius’s picture

Status: Needs work » Needs review
caesius’s picture

Issue summary: View changes
holyfire’s picture

Seriously I cannot understand how this issue remains... seriously there were comments on this EIGHT YEARS AGO.

Using an .svg logo OOTB might be something the core team really needs to think about. It's so entirely frustrating as a site builder when you run into stuff like this. User experience anyone?

cilefen’s picture

@holyfire The issue needs review based on #151's suggestions taken by @caesius.

dqd’s picture

@holyfire: "You cannot understand" is at least an admission or confession of you where others can chime in to explain to you how community momentum and initiatives work and how collective efforts and priorities decide about all task levels what happens in which time. While I kind of see what you want to say, and trust me, even the most hard working core contributors and project leaders here often say "holy... is this issue old" but! I sadly have to turn it back to you: Because in a community it isn't "the others". It is always "you and all others together".

If it was important enough for you and maybe others of you around you, you may should take a careful look at the own history of your efforts in this issue. No complaints. Just a friendly reminder how things work in an Open Source community.

At least you can find really easy work arounds in this issue how to upload an SVG and use it in a theme. So this issue is no deal-breaker at all. Just a 'lil hiccup in the theme settings UI.

jcnventura’s picture

StatusFileSize
new2.91 KB

Uploading the current state of https://git.drupalcode.org/project/drupal/-/merge_requests/1153.diff in order to use it in composer-patches.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

holyfire’s picture

@diqidoq - thank you for the comment, love to talk through this with you, feel free to PM me when you have time.

jacov’s picture

+1 can't believe this is still an issue...if we show default file as logo.svg, why we don't allow svg upload OOB.

cilefen’s picture

@jacov See comments 157, 158 and 159.

rinku jacob 13’s picture

StatusFileSize
new182.79 KB
new192.86 KB

I have successfully applied patch #160 for drupal 9.4.x version.Adding screenshots for the reference.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new151 bytes

The 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.

gauravvvv’s picture

Status: Needs work » Needs review
StatusFileSize
new2.82 KB

Updated default theme path in tests, attached patch for same. please review

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -svg, -frontend, -mobile, -dcuacs2015, -Barcelona2015 +Needs Review Queue Initiative, +Needs change record

Leaving the issue summary tag for possible cleanup.

This seems close but think the tests should be expanded to test all the extensions being added.

Also a change record should be written for it.

damienmckenna’s picture

There's a long-standing concern about allowing SVG uploads to Drupal sites due to the security problems inherent in the format. At the same time, site owners want full control over their sites and should be able to do things that could potentially be harmful to their sites because that's their decision.

There are 3rd party libraries that can filter SVG content to protect a site, but I don't see that being used here. Therefore, this would allow someone with the "administer themes" permission to upload unfiltered SVG files to the site, which would then be viewed by all visitors.

One method of absolving core developers of having to somehow protect every site from every possible security vulnerability, while also allowing individual site owners to do what they want with their own site, has been the use of "restricted access" permissions to protect certain site functionality. For example the permission for controlling field configuration is a "restricted" permission, because you could potentially open a site up to security vulnerabilities based upon how you build fields on an entity type.

The concern with this issue is that (IIRC) this would be the first part of Drupal core that officially allowed uploading SVG files to the site. However, no security tools are being added to protect the site from an unscrupulous user who discovered they'd been given the "administer themes" permission. Furthermore, the "administer themes" permission is not a "restricted" one, therefore some level of protection is warranted.

Therefore, from a security standpoint IMHO this needs further work - either an SVG security tool be added to core and properly implemented, or the "administer themes" permission be changed to a "restricted access" one.

trackleft2’s picture

@DemianMcKenna, There are definitely easy workarounds without a patch where you can upload SVG to a server via a file upload, and use via a content block.

This feature request is really just a nice to have, so site owners can use the thing they want where they expect it to be used.

We can't be the SVG police in the same way we can't be the text formatter police. The best thing we can do is to inform users that they should be concerned about arbitrarily uploading files from untrusted sources (This isn't SVG specific advice).

It was mentioned way back in #147 that we should consider rearchitecting how image toolkits are handled, but that did not seem to go over very well.

damienmckenna’s picture

We can't be the SVG police in the same way we can't be the text formatter police.

But by default Drupal does police HTML content that is rendered on the page via content inserted through text fields. Therefore, we also need to either a) provide filtering for SVG files, or b) change the permission associated with theme administration to one that puts the responsibility squarely on the head of the site owner/builder - that's what the "restricted access" permission flag indicates.

damienmckenna’s picture

Status: Needs work » Needs review
StatusFileSize
new477 bytes
new3.29 KB

This builds on #168 and changes the "administer themes" permission to be a "restricted access" permission, which IMHO would fulfill the security requirements.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -Needs issue summary update

Removing issue summary update which appeared to have been done.

Can a simple change record be written that announce svgs are now allowed?

@DamienMcKenna can we remove the Needs security review tag?

greggles’s picture

Issue tags: -Needs security review

With my "security team" hat on I agree with DamienMcKenna's prior comments that if svgs are allowed to be uploaded then we should mark that permission as "restrict access".

Is this tradeoff worth it to allow uploading of svgs in exchange for marking "administer themes" as a restricted permission?

An option to not have to add "restrict access: true" for the permission would be to filter the SVG similarly to how text formats filter text - an option for that seems to be https://www.drupal.org/project/svg_sanitizer though if we go that route we should try to also do it for core file upload fields.

Removing the "Needs security review" tag since I think Damien and I have provided that perspective, but it might need ongoing review so feel free to add back and ping if needed.

Those tradeoffs and options seem like questions for a framework or product manager.

alexpott’s picture

+++ b/core/modules/system/src/Form/ThemeSettingsForm.php
@@ -236,7 +236,9 @@ public function buildForm(array $form, FormStateInterface $form_state, $theme =
-          'file_validate_is_image' => [],
+          'file_validate_extensions' => [
+            'png gif jpg jpeg apng svg',
+          ],

This will need updating for https://www.drupal.org/node/3363700

greggles’s picture

Title: Unnecessary restrictions on logo format: Can't upload replacement SVG logo » Support SVG files for theme logo setting
Category: Bug report » Feature request

Making title more descriptive and changing category. IMO this seems like a feature, to add support for more formats.

joegraduate’s picture

Status: Needs work » Needs review
StatusFileSize
new3.28 KB

Re-rolled #173 and made change suggested in #177.

smustgrave’s picture

Status: Needs review » Needs work

With patches please include an interdiff. Also if possible MRs are recommended now too.

But moving to NW for the change record.

manikandank03’s picture

The patch #179 works fine with latest Drupal 10.2.2 with PHP 8.2

thejimbirch’s picture

So to clarify, this just needs a change record and the patch in #179 turned into a merge request to move it forward?

thejimbirch changed the visibility of the branch 2259567-parsonsj to hidden.

thejimbirch changed the visibility of the branch 2259567-unnecessary-restrictions-on to hidden.

thejimbirch’s picture

Hid some stale files and stale merge requests that were against 9.2 and 9.3.

greggles’s picture

Issue summary: View changes

I don't think that's quite it, but that would be helpful.

I updated the issue summary to remove an outdated remaining task and add some option items from comment 176.

thejimbirch changed the visibility of the branch 9.2.x to hidden.

thejimbirch changed the visibility of the branch 10.2.x to hidden.

thejimbirch changed the visibility of the branch 10.3.x to hidden.

thejimbirch changed the visibility of the branch 11.x to hidden.

twills made their first commit to this issue’s fork.

twills’s picture

Status: Needs work » Needs review

MR Added created from patch in comment 179. Draft change record created.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -Needs change record

Hiding the patch as the work is in the MR now.

Unfortunately think the test needs to be tweaked some as it seems to be passing without the update. See https://git.drupalcode.org/issue/drupal-2259567/-/jobs/1161166

Testing manually though when I upload a svg it doesn't appear to render.

Was on standard profile using olivero as frontend theme.

Removing tag for CR.

Edit:

Seems my svg was corrupt. Using a 2nd I am able to upload correctly.

smustgrave’s picture

Status: Needs work » Reviewed & tested by the community

Ah found out the problem. The svg wasn’t saving but that wasn’t being checked if the form threw any errors. And when it went to check the logo_path it had the old image png value which was valid because the form never saved.

I added an assertion for the verification message the form saved

But also cleared the logo at the end of the loop so new value can be added and doesn't fall back to the previous image in the loop.

We now get a test only failure https://git.drupalcode.org/issue/drupal-2259567/-/jobs/1163711

Didn't make any change to the solution so think I'm fine with marking

catch’s picture

Status: Reviewed & tested by the community » Needs review

Back to needs review for that question. I feel like allowing someone to administer themes allows them to deface your site, apart from their ability to upload malicious SVGs, so it probably make sense to add it?

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Responded

alexpott’s picture

Trying to sort out issue credit. I've tried to credit everyone who has moved this issue on over years with patches, helpful comments. mentoring at cons, working on it at cons. If I've made a mistake please let me know.

alexpott’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed

Drupal does provide ample footguns especially behind the restrict access type permissions. I think that this functionality is expected out-of-the-box and therefore we should support it.

Committed and pushed 537f11dcb5 to 11.x and 340845698d to 10.3.x. Thanks!

  • alexpott committed 34084569 on 10.3.x
    Issue #2259567 by jcnventura, eelkeblok, joegraduate, thejimbirch,...

  • alexpott committed 537f11dc on 11.x
    Issue #2259567 by jcnventura, eelkeblok, joegraduate, thejimbirch,...
alexpott’s picture

I'm a little bit amused that we've supported svg upload in favicon since #864938: Can't upload .ico favicon... TIL.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.