CVE-2022-24749: Sylius/sylius Cross-Site Scripting Vulnerability

MODERATE
Advisory Identifier: GHSA-4qrp-27r3-66fj
CVSS 6.1
CWE-80 CWE-434 CWE-79
Published
Advisory Summary

CVE-2022-24749 is a MODERATE (CVSS 6.1) cross-site scripting vulnerability (CWE-80: Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS)) affecting Sylius/sylius libraries in the Packagist ecosystem. The issue involves improper sanitize of svg files during content upload ('cross-site scripting') in sylius/sylius. Remediation is available by upgrading affected packages to version 1.9.10, 1.10.11, 1.11.2.

CVE-2022-24749 at a Glance

CVE Identifier CVE-2022-24749
GHSA Identifier GHSA-4qrp-27r3-66fj
Severity MODERATE
CVSS v3.1 Base Score 6.1
CWE Classification CWE-80: Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS)
Affected Product Sylius/sylius
Package Ecosystem Packagist
Published Date
Last Updated

Security Impact

CVSS: 6.1

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Changed (S:C)
Confidentiality Low (C:L)
Integrity Low (I:L)
Availability None (A:N)

How to Fix CVE-2022-24749

To remediate this vulnerability, upgrade all affected Sylius/sylius dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

sylius/sylius fixed: 1.9.10
Upgrade sylius/sylius to 1.9.10
sylius/sylius fixed: 1.10.11
Upgrade sylius/sylius to 1.10.11
sylius/sylius fixed: 1.11.2
Upgrade sylius/sylius to 1.11.2
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for sylius/sylius

How to Check if You Are Affected

To determine whether your application is affected by CVE-2022-24749, inspect your project dependencies for Sylius/sylius:

inspect dependencies for sylius/sylius

Analyze the terminal output to locate any version of Sylius/sylius in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.9.10), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-80: Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS), where the product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special characters such as "<", ">", and "&" that could be interpreted as web-scripting elements when they are sent to a downstream component that processes web pages. In Sylius/sylius, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Impact There is a possibility to upload an SVG file containing XSS code in the admin panel. In order to perform an XSS attack, the file itself has to be opened in a new card (or loaded outside of the IMG tag). The problem applies both to the files opened on the admin panel and shop pages. ### Patches The issue is fixed in versions: 1.9.10, 1.10.11, 1.11.2, and above. ### Workarounds If there is a need to upload an SVG image type, on-upload sanitization has to be added. The way to achieve this is to require a library that will do the trick: ``` composer require enshrined/svg-sanitize ``` The second step is all about performing a file content sanitization before writing it to the filesystem. It can be done by overwriting the service: ```php <?php declare(strict_types=1); namespace App\Uploader; use enshrined\svgSanitize\Sanitizer; use Gaufrette\Filesystem; use Sylius\Component\Core\Generator\ImagePathGeneratorInterface; use Sylius\Component\Core\Generator\UploadedImagePathGenerator; use Sylius\Component\Core\Model\ImageInterface; use Sylius\Component\Core\Uploader\ImageUploaderInterface; use Symfony\Component\HttpFoundation\File\File; use Webmozart\Assert\Assert; final class ImageUploader implements ImageUploaderInterface { private const MIME_SVG_XML = 'image/svg+xml'; private const MIME_SVG = 'image/svg'; /** @var Filesystem */ protected $filesystem; /** @var ImagePathGeneratorInterface */ protected $imagePathGenerator; /** @var Sanitizer */ protected $sanitizer; public function __construct( Filesystem $filesystem, ?ImagePathGeneratorInterface $imagePathGenerator = null ) { $this->filesystem = $filesystem; if ($imagePathGenerator === null) { @trigger_error(sprintf( 'Not passing an $imagePathGenerator to %s constructor is deprecated since Sylius 1.6 and will be not possible in Sylius 2.0.', self::class ), \E_USER_DEPRECATED); } $this->imagePathGenerator = $imagePathGenerator ?? new UploadedImagePathGenerator(); $this->sanitizer = new Sanitizer(); } public function upload(ImageInterface $image): void { if (!$image->hasFile()) { return; } /** @var File $file */ $file = $image->getFile(); Assert::isInstanceOf($file, File::class); $fileContent = $this->sanitizeContent(file_get_contents($file->getPathname()), $file->getMimeType()); if (null !== $image->getPath() && $this->has($image->getPath())) { $this->remove($image->getPath()); } do { $path = $this->imagePathGenerator->generate($image); } while ($this->isAdBlockingProne($path) || $this->filesystem->has($path)); $image->setPath($path); $this->filesystem->write($image->getPath(), $fileContent); } public function remove(string $path): bool { if ($this->filesystem->has($path)) { return $this->filesystem->delete($path); } return false; } protected function sanitizeContent(string $fileContent, string $mimeType): string { if (self::MIME_SVG_XML === $mimeType || self::MIME_SVG === $mimeType) { $fileContent = $this->sanitizer->sanitize($fileContent); } return $fileContent; } private function has(string $path): bool { return $this->filesystem->has($path); } /** * Will return true if the path is prone to be blocked by ad blockers */ private function isAdBlockingProne(string $path): bool { return strpos($path, 'ad') !== false; } } ``` After that, register service in the container: ```yaml services: sylius.image_uploader: class: App\Uploader\ImageUploader arguments: - '@gaufrette.sylius_image_filesystem' - '@Sylius\Component\Core\Generator\ImagePathGeneratorInterface' ``` ### For more information If you have any questions or comments about this advisory: * Open an issue in [Sylius issues](https://github.com/Sylius/Sylius/issues) * Email us at security@sylius.com

CVE-2022-24749 Affected Sylius/sylius Versions

3 component(s)
Fixed Versions:
1.9.101.10.111.11.2
Product / Package Ecosystem Affected Versions Fixed Version
sylius/sylius
Packagist
< 1.9.10
1.9.10
sylius/sylius
Packagist
≥ 1.10.0
< 1.10.11
1.10.11
sylius/sylius
Packagist
≥ 1.11.0
< 1.11.2
1.11.2

References

Frequently Asked Questions

What is CVE-2022-24749?
CVE-2022-24749 is a security vulnerability in Sylius/sylius involving Improper sanitize of SVG files during content upload ('Cross-site Scripting') in sylius/sylius under CWE-80: Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS).
Which Sylius/sylius versions are affected?
Affected versions include releases prior to 1.9.10, 1.10.11, 1.11.2 across affected packages: sylius/sylius.
What version fixes CVE-2022-24749?
Upgrading to 1.9.10, 1.10.11, 1.11.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is sylius/sylius affected?
Yes, sylius/sylius is affected in releases prior to 1.9.10, 1.10.11, 1.11.2. Upgrade your dependency to 1.9.10, 1.10.11, 1.11.2 or later.
What is the CVSS score of CVE-2022-24749?
CVE-2022-24749 has a CVSS v3.1 base score of 6.1 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N.
What CWE is associated with CVE-2022-24749?
CVE-2022-24749 is classified under CWE-80: Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) (The product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special characters such as "<", ">", and "&" that could be interpreted as web-scripting elements when they are sent to a downstream component that processes web pages.).
How can I check Packagist dependencies for CVE-2022-24749?
Run the dependency tree command: 'inspect dependencies for sylius/sylius'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-4qrp-27r3-66fj",
  "modified" : "2022-03-18T15:22:18Z",
  "published" : "2022-03-14T22:38:14Z",
  "aliases" : [ "CVE-2022-24749" ],
  "summary" : "Improper sanitize of SVG files during content upload ('Cross-site Scripting') in sylius/sylius",
  "details" : "### Impact\nThere is a possibility to upload an SVG file containing XSS code in the admin panel. In order to perform an XSS attack, the file itself has to be opened in a new card (or loaded outside of the IMG tag). The problem applies both to the files opened on the admin panel and shop pages.\n\n### Patches\nThe issue is fixed in versions: 1.9.10, 1.10.11, 1.11.2, and above.\n\n### Workarounds\nIf there is a need to upload an SVG image type, on-upload sanitization has to be added. The way to achieve this is to require a library that will do the trick:\n\n```\ncomposer require enshrined/svg-sanitize\n```\n\nThe second step is all about performing a file content sanitization before writing it to the filesystem. It can be done by overwriting the service:\n\n```php\n<?php\n\ndeclare(strict_types=1);\n\nnamespace App\\Uploader;\n\nuse enshrined\\svgSanitize\\Sanitizer;\nuse Gaufrette\\Filesystem;\nuse Sylius\\Component\\Core\\Generator\\ImagePathGeneratorInterface;\nuse Sylius\\Component\\Core\\Generator\\UploadedImagePathGenerator;\nuse Sylius\\Component\\Core\\Model\\ImageInterface;\nuse Sylius\\Component\\Core\\Uploader\\ImageUploaderInterface;\nuse Symfony\\Component\\HttpFoundation\\File\\File;\nuse Webmozart\\Assert\\Assert;\n\nfinal class ImageUploader implements ImageUploaderInterface\n{\n    private const MIME_SVG_XML = 'image/svg+xml';\n    private const MIME_SVG = 'image/svg';\n\n    /** @var Filesystem */\n    protected $filesystem;\n\n    /** @var ImagePathGeneratorInterface */\n    protected $imagePathGenerator;\n\n    /** @var Sanitizer */\n    protected $sanitizer;\n\n    public function __construct(\n        Filesystem $filesystem,\n        ?ImagePathGeneratorInterface $imagePathGenerator = null\n    ) {\n        $this->filesystem = $filesystem;\n\n        if ($imagePathGenerator === null) {\n            @trigger_error(sprintf(\n                'Not passing an $imagePathGenerator to %s constructor is deprecated since Sylius 1.6 and will be not possible in Sylius 2.0.', self::class\n            ), \\E_USER_DEPRECATED);\n        }\n\n        $this->imagePathGenerator = $imagePathGenerator ?? new UploadedImagePathGenerator();\n        $this->sanitizer = new Sanitizer();\n    }\n\n    public function upload(ImageInterface $image): void\n    {\n        if (!$image->hasFile()) {\n            return;\n        }\n\n        /** @var File $file */\n        $file = $image->getFile();\n\n        Assert::isInstanceOf($file, File::class);\n\n        $fileContent = $this->sanitizeContent(file_get_contents($file->getPathname()), $file->getMimeType());\n\n        if (null !== $image->getPath() && $this->has($image->getPath())) {\n            $this->remove($image->getPath());\n        }\n\n        do {\n            $path = $this->imagePathGenerator->generate($image);\n        } while ($this->isAdBlockingProne($path) || $this->filesystem->has($path));\n\n        $image->setPath($path);\n\n        $this->filesystem->write($image->getPath(), $fileContent);\n    }\n\n    public function remove(string $path): bool\n    {\n        if ($this->filesystem->has($path)) {\n            return $this->filesystem->delete($path);\n        }\n\n        return false;\n    }\n\n    protected function sanitizeContent(string $fileContent, string $mimeType): string\n    {\n        if (self::MIME_SVG_XML === $mimeType || self::MIME_SVG === $mimeType) {\n            $fileContent = $this->sanitizer->sanitize($fileContent);\n        }\n\n        return $fileContent;\n    }\n\n    private function has(string $path): bool\n    {\n        return $this->filesystem->has($path);\n    }\n\n    /**\n     * Will return true if the path is prone to be blocked by ad blockers\n     */\n    private function isAdBlockingProne(string $path): bool\n    {\n        return strpos($path, 'ad') !== false;\n    }\n}\n```\n\nAfter that, register service in the container:\n\n```yaml\nservices:\n    sylius.image_uploader:\n        class: App\\Uploader\\ImageUploader\n        arguments:\n            - '@gaufrette.sylius_image_filesystem'\n            - '@Sylius\\Component\\Core\\Generator\\ImagePathGeneratorInterface'\n```\n\n### For more information\nIf you have any questions or comments about this advisory:\n* Open an issue in [Sylius issues](https://github.com/Sylius/Sylius/issues)\n* Email us at security@sylius.com\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "sylius/sylius"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.9.10"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "sylius/sylius"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "1.10.0"
      }, {
        "fixed" : "1.10.11"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "sylius/sylius"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "1.11.0"
      }, {
        "fixed" : "1.11.2"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/Sylius/Sylius/security/advisories/GHSA-4qrp-27r3-66fj"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-24749"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/Sylius/Sylius"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Sylius/Sylius/releases/tag/v1.10.11"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Sylius/Sylius/releases/tag/v1.11.2"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Sylius/Sylius/releases/tag/v1.9.10"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-434", "CWE-79", "CWE-80" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-03-14T22:38:14Z",
    "nvd_published_at" : "2022-03-14T22:15:00Z"
  }
}