CVE-2021-37711 (published 2021-08-16T23:15Z)

Versions prior to 6.4.3.1 contain an authenticated server-side request forgery vulnerability in file upload via URL. Version 6.4.3.1 contains a patch. As workarounds for older versions of 6.1, 6.2, and 6.3, corresponding security measures are also available via a plugin.

Severity: MEDIUM
CVSS v2 base score: 6.5 (AV:N/AC:L/Au:S/C:P/I:P/A:P)
CVSS v3 base score: 8.8, HIGH (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-918
cwe_name: Server-Side Request Forgery (SSRF)
description: The web server receives a URL or similar request from an upstream component and retrieves the contents of this URL, but it does not sufficiently ensure that the request is being sent to the expected destination.
extended_description: By providing URLs to unexpected hosts or ports, attackers can make it appear that the server is sending the request, possibly bypassing access controls such as firewalls that prevent the attackers from accessing the URLs directly. The server can be used as a proxy to conduct port scanning of hosts in internal networks, use other URLs such as that can access documents on the system (using file://), or use other protocols such as gopher:// or tftp://, which may provide greater control over the contents of requests.
         

Fix information:
repo_url: https://github.com/shopware/platform
commit_details: repo_url: https://github.com/shopware/platform
author: Jonas Elfering
author_date: 2021-07-27 08:03:48+02:00
msg: NEXT-15673 - Fix file upload ip validation for IPv6
repository: repo_url: https://github.com/shopware/platform
repo_name: shopware/shopware
description: Shopware 6 is an open commerce platform based on Symfony Framework and Vue and supported by a worldwide community and more than 1.500 community extensions
repo_language: PHP
owner: shopware
file_changes: filename: FileUrlValidator.php
change_type: ModificationType.MODIFY
diff: @@ -17,6 +17,11 @@ class FileUrlValidator implements FileUrlValidatorInterface
         // Potentially IPv6
         $ip = trim($ip, '[]');
 
+        return $this->validateIp($ip);
+    }
+
+    private function validateIp(string $ip): bool
+    {
         $ip = filter_var(
             $ip,
             \FILTER_VALIDATE_IP,
@@ -27,6 +32,27 @@ class FileUrlValidator implements FileUrlValidatorInterface
             return false;
         }
 
+        if (!filter_var($ip, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
+            return true;
+        }
+
+        // Convert IPv6 to packed format and back so we can check if there is a IPv4 representation of the IP
+        $packedIp = inet_pton($ip);
+        if (!$packedIp) {
+            return false;
+        }
+        $convertedIp = inet_ntop($packedIp);
+        if (!$convertedIp) {
+            return false;
+        }
+        $convertedIp = explode(':', $convertedIp);
+        $ipv4 = array_pop($convertedIp);
+
+        // Additionally filter IPv4 representation of the IP
+        if (filter_var($ipv4, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4)) {
+            return $this->validateIp($ipv4);
+        }
+
         return true;
     }
 }

programming_language: PHP
filename: FileUrlValidatorTest.php
change_type: ModificationType.ADD
diff: @@ -0,0 +1,37 @@
+<?php declare(strict_types=1);
+
+namespace Shopware\Core\Content\Test\Media\File;
+
+use PHPUnit\Framework\TestCase;
+use Shopware\Core\Content\Media\File\FileUrlValidator;
+
+class FileUrlValidatorTest extends TestCase
+{
+    /**
+     * @dataProvider fileSourceProvider
+     */
+    public function testIsValid(string $source, bool $expectedResult): void
+    {
+        $validator = new FileUrlValidator();
+
+        static::assertEquals($expectedResult, $validator->isValid($source));
+    }
+
+    public function fileSourceProvider(): array
+    {
+        return [
+            'reserved IPv4' => ['https://127.0.0.1', false],
+            'converted reserved IPv4' => ['https://0:0:0:0:0:FFFF:7F00:0001', false],
+            'reserved IPv4 mapped to IPv6' => ['https://[0:0:0:0:0:FFFF:127.0.0.1]', false],
+            'reserved IPv6' => ['https://FE80::', false],
+            'private IPv4' => ['https://192.168.0.0', false],
+            'converted private IPv4' => ['https://0:0:0:0:0:FFFF:C0A8:0000', false],
+            'private IPv4 mapped to IPv6' => ['https://[0:0:0:0:0:FFFF:192.168.0.0]', false],
+            'private IPv6' => ['https://FC00::', false],
+            'invalid IPv4' => ['https://378.0.0.1', false],
+            'valid IPv4' => ['https://8.8.8.8', true],
+            'valid IPv6' => ['https://2001:db8::8a2e:370:7334', true],
+            'valid IPv6 URL' => ['https://[2001:db8::8a2e:370:7334]', true],
+        ];
+    }
+}

programming_language: PHP