File type .svg Error in image upload Magento 2.3.1

The reason SVG's are disabled in Magento 2 by default, is for security reasons such as stored XSS. And I would recommend that you leave them disabled atleast for now until we get better sanitization for them.

You can see an example of this in APPSEC-1673, where they removed SVGs in the favicon

https://magento.com/security/patches/magento-2016-and-219-security-update

APPSEC-1673 Stored xss using svg images in Favicon.

While you can't upload SVG's via the backend, you can still upload them with FTP and reference them as if you did upload them. This way you still get the benefits of using SVG's but you don't have to deal with the security issues of allowing users to load them.

Enable SVG upload for Favicon/Logo upload

But if you do still want to enable SVG upload for the favicon/logo upload. You can create a custom module and override xml nodes/php functions where it was removed from. You can find these in the diff below

https://github.com/magento/magento2/compare/2.1.8...2.1.9

Enable SVG elsewhere

Dependent on where you want to enable SVG uploads will affect what files you will need to override. You should be able to find the files you need to edit by a quick search for allowedExtensions in XML files or either getAllowedExtensions setAllowedExtensions in PHP files.


open OR overwrite below file and code <item name="svg" xsi:type="string">text/html</item>

/vendor/magento/module-cms/etc/di.xml

<type name="Magento\Cms\Model\Wysiwyg\Images\Storage">
    <arguments>
        <argument name="extensions" xsi:type="array">
            <item name="allowed" xsi:type="array">
                ......
                <item name="svg" xsi:type="string">text/html</item>
                ......
            </item>
            <item name="image_allowed" xsi:type="array">
                ......
                <item name="svg" xsi:type="string">text/html</item>
                ......
            </item>
            <item name="media_allowed" xsi:type="array">
                ......
                <item name="svg" xsi:type="string">text/html</item>
                ......
            </item>
        </argument>
    </arguments>
</type>

If you use below magento 2.3 version , code silde change . Replace above code <item name="svg" xsi:type="string">text/html</item> To <item name="svg" xsi:type="number">1</item>


Open Below File

/vendor/magento/module-cms/etc/di.xml

Add your extension you want to allow

<item name="svg" xsi:type="number">1</item>

<argument name="extensions" xsi:type="array">
    <item name="allowed" xsi:type="array">
        <item name="jpg" xsi:type="number">1</item>
        <item name="jpeg" xsi:type="number">1</item>
        <item name="png" xsi:type="number">1</item>
        <item name="gif" xsi:type="number">1</item>
        <item name="svg" xsi:type="number">1</item>
    </item>
    <item name="image_allowed" xsi:type="array">
        <item name="jpg" xsi:type="number">1</item>
        <item name="jpeg" xsi:type="number">1</item>
        <item name="png" xsi:type="number">1</item>
        <item name="gif" xsi:type="number">1</item>
    </item>
    <item name="media_allowed" xsi:type="array">
        <item name="flv" xsi:type="number">1</item>
        <item name="swf" xsi:type="number">1</item>
        <item name="avi" xsi:type="number">1</item>
        <item name="mov" xsi:type="number">1</item>
        <item name="rm" xsi:type="number">1</item>
        <item name="wmv" xsi:type="number">1</item>
    </item>
</argument>