CVE-2022-24752: Sylius/grid bundle DQL Injection Through Sorting Parameters Vulnerability

CRITICAL
Advisory Identifier: GHSA-2xmm-g482-4439
CVSS 9.8
CWE-89
Published
Advisory Summary

CVE-2022-24752 is a CRITICAL (CVSS 9.8) dql injection through sorting parameters vulnerability (CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')) affecting Sylius/grid bundle libraries in the Packagist ecosystem. The issue involves dql injection through sorting parameters blocked. Remediation is available by upgrading affected packages to version 1.10.1.

CVE-2022-24752 at a Glance

CVE Identifier CVE-2022-24752
GHSA Identifier GHSA-2xmm-g482-4439
Severity CRITICAL
CVSS v3.1 Base Score 9.8
CWE Classification CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
Affected Product Sylius/grid bundle
Package Ecosystem Packagist
Published Date
Last Updated

Security Impact

CVSS: 9.8

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:N/S:U/C:H/I:H/A:H).

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

How to Fix CVE-2022-24752

To remediate this vulnerability, upgrade all affected Sylius/grid bundle 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/grid-bundle fixed: 1.10.1
Upgrade sylius/grid-bundle to 1.10.1
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/grid-bundle

How to Check if You Are Affected

To determine whether your application is affected by CVE-2022-24752, inspect your project dependencies for Sylius/grid bundle:

inspect dependencies for sylius/grid-bundle

Analyze the terminal output to locate any version of Sylius/grid bundle in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.10.1), 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-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where the product constructs all or part of an sql command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended sql command when it is sent to a downstream component. without sufficient removal or quoting of sql syntax in user-controllable inputs, the generated sql query can cause those inputs to be interpreted as sql instead of ordinary user data. In Sylius/grid bundle, 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 Values added at the end of query sorting were passed directly to the DB. We don't know, if it could lead to direct SQL injections, however, we should not allow for easy injection of values there anyway. ### Patches The issue is fixed in version 1.10.1 and in 1.11-rc.1 ### Workarounds You have to overwrite your `Sylius\Component\Grid\Sorting\Sorter.php` class: ```php <?php // src/App/Sorting/Sorter.php declare(strict_types=1); namespace App\Sorting; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Sylius\Component\Grid\Data\DataSourceInterface; use Sylius\Component\Grid\Definition\Grid; use Sylius\Component\Grid\Parameters; use Sylius\Component\Grid\Sorting\SorterInterface; final class Sorter implements SorterInterface { public function sort(DataSourceInterface $dataSource, Grid $grid, Parameters $parameters): void { $enabledFields = $grid->getFields(); $expressionBuilder = $dataSource->getExpressionBuilder(); $sorting = $parameters->get('sorting', $grid->getSorting()); $this->validateSortingParams($sorting, $enabledFields); foreach ($sorting as $field => $order) { $this->validateFieldNames($field, $enabledFields); $gridField = $grid->getField($field); $property = $gridField->getSortable(); if (null !== $property) { $expressionBuilder->addOrderBy($property, $order); } } } private function validateSortingParams(array $sorting, array $enabledFields): void { foreach (array_keys($enabledFields) as $key) { if (array_key_exists($key, $sorting) && !in_array($sorting[$key], ['asc', 'desc'])) { throw new BadRequestHttpException(sprintf('%s is not valid, use asc or desc instead.', $sorting[$key])); } } } private function validateFieldNames(string $fieldName, array $enabledFields): void { $enabledFieldsNames = array_keys($enabledFields); if (!in_array($fieldName, $enabledFieldsNames, true)) { throw new BadRequestHttpException(sprintf('%s is not valid field, did you mean one of these: %s?', $fieldName, implode(', ', $enabledFieldsNames))); } } } ``` and register it in your container: ```yaml # config/services.yaml services: # ... sylius.grid.sorter: class: App\Sorting\Sorter ``` ### 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](mailto:security@sylius.com)

CVE-2022-24752 Affected Sylius/grid bundle Versions

1 component(s)
Fixed Versions:
1.10.1
Product / Package Ecosystem Affected Versions Fixed Version
sylius/grid-bundle
Packagist
< 1.10.1
1.10.1

References

Frequently Asked Questions

What is CVE-2022-24752?
CVE-2022-24752 is a security vulnerability in Sylius/grid bundle involving DQL injection through sorting parameters blocked under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
Which Sylius/grid bundle versions are affected?
Affected versions include releases prior to 1.10.1 across affected packages: sylius/grid-bundle.
What version fixes CVE-2022-24752?
Upgrading to 1.10.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is sylius/grid-bundle affected?
Yes, sylius/grid-bundle is affected in releases prior to 1.10.1. Upgrade your dependency to 1.10.1 or later.
What is the CVSS score of CVE-2022-24752?
CVE-2022-24752 has a CVSS v3.1 base score of 9.8 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2022-24752?
CVE-2022-24752 is classified under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.).
How can I check Packagist dependencies for CVE-2022-24752?
Run the dependency tree command: 'inspect dependencies for sylius/grid-bundle'. 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-2xmm-g482-4439",
  "modified" : "2022-03-15T19:09:16Z",
  "published" : "2022-03-15T19:09:16Z",
  "aliases" : [ "CVE-2022-24752" ],
  "summary" : "DQL injection through sorting parameters blocked",
  "details" : "### Impact\nValues added at the end of query sorting were passed directly to the DB. We don't know, if it could lead to direct SQL injections, however, we should not allow for easy injection of values there anyway.\n\n### Patches\nThe issue is fixed in version 1.10.1 and in 1.11-rc.1\n\n### Workarounds\n\nYou have to overwrite your `Sylius\\Component\\Grid\\Sorting\\Sorter.php` class:\n\n```php\n<?php\n\n// src/App/Sorting/Sorter.php\n\ndeclare(strict_types=1);\n\nnamespace App\\Sorting;\n\nuse Symfony\\Component\\HttpKernel\\Exception\\BadRequestHttpException;\nuse Sylius\\Component\\Grid\\Data\\DataSourceInterface;\nuse Sylius\\Component\\Grid\\Definition\\Grid;\nuse Sylius\\Component\\Grid\\Parameters;\nuse Sylius\\Component\\Grid\\Sorting\\SorterInterface;\n\nfinal class Sorter implements SorterInterface\n{\n    public function sort(DataSourceInterface $dataSource, Grid $grid, Parameters $parameters): void\n    {\n        $enabledFields = $grid->getFields();\n        $expressionBuilder = $dataSource->getExpressionBuilder();\n\n        $sorting = $parameters->get('sorting', $grid->getSorting());\n        $this->validateSortingParams($sorting, $enabledFields);\n\n        foreach ($sorting as $field => $order) {\n            $this->validateFieldNames($field, $enabledFields);\n\n            $gridField = $grid->getField($field);\n            $property = $gridField->getSortable();\n\n            if (null !== $property) {\n                $expressionBuilder->addOrderBy($property, $order);\n            }\n        }\n    }\n\n    private function validateSortingParams(array $sorting, array $enabledFields): void\n    {\n        foreach (array_keys($enabledFields) as $key) {\n            if (array_key_exists($key, $sorting) && !in_array($sorting[$key], ['asc', 'desc'])) {\n                throw new BadRequestHttpException(sprintf('%s is not valid, use asc or desc instead.', $sorting[$key]));\n            }\n        }\n    }\n\n    private function validateFieldNames(string $fieldName, array $enabledFields): void\n    {\n        $enabledFieldsNames = array_keys($enabledFields);\n\n        if (!in_array($fieldName, $enabledFieldsNames, true)) {\n            throw new BadRequestHttpException(sprintf('%s is not valid field, did you mean one of these: %s?', $fieldName, implode(', ', $enabledFieldsNames)));\n        }\n    }\n}\n```\nand register it in your container: \n\n```yaml\n# config/services.yaml\nservices:\n    # ...\n    sylius.grid.sorter:\n        class: App\\Sorting\\Sorter\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](mailto:security@sylius.com)",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "sylius/grid-bundle"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.10.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/Sylius/SyliusGridBundle/security/advisories/GHSA-2xmm-g482-4439"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-24752"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Sylius/SyliusGridBundle/pull/222"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Sylius/SyliusGridBundle/commit/73d0791d0575f955e830a3da4c3345f420d2f784"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/Sylius/SyliusGridBundle"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Sylius/SyliusGridBundle/releases/tag/v1.10.1"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Sylius/SyliusGridBundle/releases/tag/v1.11.0-RC.2"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-89" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-03-15T19:09:16Z",
    "nvd_published_at" : "2022-03-15T15:15:00Z"
  }
}