CVE-2022-23614: Twig/twig Code Injection Vulnerability

HIGH
Advisory Identifier: GHSA-5mv2-rx3q-4w2v
CVSS 8.8
CWE-94 CWE-74
Published
Advisory Summary

CVE-2022-23614 is a HIGH (CVSS 8.8) code injection vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Twig/twig libraries in the Packagist ecosystem. The issue involves code injection in twig. Remediation is available by upgrading affected packages to version 2.14.11, 3.3.8.

CVE-2022-23614 at a Glance

CVE Identifier CVE-2022-23614
GHSA Identifier GHSA-5mv2-rx3q-4w2v
Severity HIGH
CVSS v3.1 Base Score 8.8
CWE Classification CWE-94: Improper Control of Generation of Code ('Code Injection')
Affected Product Twig/twig
Package Ecosystem Packagist
Published Date
Last Updated

Security Impact

CVSS: 8.8

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

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required Low (PR:L)
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-23614

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

twig/twig fixed: 2.14.11
Upgrade twig/twig to 2.14.11
twig/twig fixed: 3.3.8
Upgrade twig/twig to 3.3.8
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 twig/twig

How to Check if You Are Affected

To determine whether your application is affected by CVE-2022-23614, inspect your project dependencies for Twig/twig:

inspect dependencies for twig/twig

Analyze the terminal output to locate any version of Twig/twig in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.14.11), 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-94: Improper Control of Generation of Code ('Code Injection'), where the product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. In Twig/twig, 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

# Description When in a sandbox mode, the `arrow` parameter of the `sort` filter must be a closure to avoid attackers being able to run arbitrary PHP functions. # Resolution We now disallow calling non Closure in the `sort` filter like we already did for some other filters. # Credits We would like to thank Marlon Starkloff for reporting the issue and Fabien Potencier for fixing the issue.

CVE-2022-23614 Affected Twig/twig Versions

2 component(s)
Fixed Versions:
2.14.113.3.8
Product / Package Ecosystem Affected Versions Fixed Version
twig/twig
Packagist
≥ 2.0.0
< 2.14.11
2.14.11
twig/twig
Packagist
≥ 3.0.0
< 3.3.8
3.3.8

References

GitHub Advisory / Wiki ADVISORY
https://github.com/twigphp/Twig/security/advisories/GHSA-5mv2-rx3q-4w2v
NVD — CVE-2022-23614 NVD
https://nvd.nist.gov/vuln/detail/CVE-2022-23614
Security Fix Commit FIX COMMIT
https://github.com/twigphp/Twig/commit/22b9dc3c03ee66d7e21d9ed2ca76052b134cb9e9
Security Fix Commit FIX COMMIT
https://github.com/twigphp/Twig/commit/2eb33080558611201b55079d07ac88f207b466d5
Twig/twig Source Repository REPOSITORY
https://github.com/FriendsOfPHP/security-advisories/blob/master/twig/twig/CVE-2022-23614.yaml
Twig/twig Source Repository REPOSITORY
https://github.com/twigphp/Twig
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/I2PVV5DUTRUECTIHMTWRI5Z7DVNYQ2YO
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/OTN4273U4RHVIXED64T7DSMJ3VYTPRE7
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/PECHIY2XLWUH2WLCNPDGNFMPHPRPCEDZ
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/SIGZCFSYLPP7UVJ4E4NLHSOQSKYNXSAD
Twig/twig Release RELEASE
https://symfony.com/blog/twig-security-release-disallow-non-closures-in-the-sort-filter
Twig/twig Security Information SECURITY
https://www.debian.org/security/2022/dsa-5107

Frequently Asked Questions

What is CVE-2022-23614?
CVE-2022-23614 is a security vulnerability in Twig/twig involving Code injection in Twig under CWE-94: Improper Control of Generation of Code ('Code Injection').
Which Twig/twig versions are affected?
Affected versions include releases prior to 2.14.11, 3.3.8 across affected packages: twig/twig.
What version fixes CVE-2022-23614?
Upgrading to 2.14.11, 3.3.8 (or the latest patched release for your respective branch) resolves the vulnerability.
Is twig/twig affected?
Yes, twig/twig is affected in releases prior to 2.14.11, 3.3.8. Upgrade your dependency to 2.14.11, 3.3.8 or later.
What is the CVSS score of CVE-2022-23614?
CVE-2022-23614 has a CVSS v3.1 base score of 8.8 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2022-23614?
CVE-2022-23614 is classified under CWE-94: Improper Control of Generation of Code ('Code Injection') (The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.).
How can I check Packagist dependencies for CVE-2022-23614?
Run the dependency tree command: 'inspect dependencies for twig/twig'. 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-5mv2-rx3q-4w2v",
  "modified" : "2022-02-11T19:16:32Z",
  "published" : "2022-02-10T22:21:48Z",
  "aliases" : [ "CVE-2022-23614" ],
  "summary" : "Code injection in Twig",
  "details" : "# Description\n\nWhen in a sandbox mode, the `arrow` parameter of the `sort` filter must be a closure to avoid attackers being able to run arbitrary PHP functions.\n\n# Resolution\n\nWe now disallow calling non Closure in the `sort` filter like we already did for some other filters.\n\n# Credits\n\nWe would like to thank Marlon Starkloff for reporting the issue and Fabien Potencier for fixing the issue.\n ",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "twig/twig"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.0.0"
      }, {
        "fixed" : "2.14.11"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "twig/twig"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "3.0.0"
      }, {
        "fixed" : "3.3.8"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/twigphp/Twig/security/advisories/GHSA-5mv2-rx3q-4w2v"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-23614"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/twigphp/Twig/commit/22b9dc3c03ee66d7e21d9ed2ca76052b134cb9e9"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/twigphp/Twig/commit/2eb33080558611201b55079d07ac88f207b466d5"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/FriendsOfPHP/security-advisories/blob/master/twig/twig/CVE-2022-23614.yaml"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/twigphp/Twig"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/I2PVV5DUTRUECTIHMTWRI5Z7DVNYQ2YO"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/OTN4273U4RHVIXED64T7DSMJ3VYTPRE7"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/PECHIY2XLWUH2WLCNPDGNFMPHPRPCEDZ"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/SIGZCFSYLPP7UVJ4E4NLHSOQSKYNXSAD"
  }, {
    "type" : "WEB",
    "url" : "https://symfony.com/blog/twig-security-release-disallow-non-closures-in-the-sort-filter"
  }, {
    "type" : "WEB",
    "url" : "https://www.debian.org/security/2022/dsa-5107"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-74", "CWE-94" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-02-07T16:43:09Z",
    "nvd_published_at" : "2022-02-04T23:15:00Z"
  }
}