CVE-2024-51755: Twig/twig Twig Has Unguarded Calls To Vulnerability

LOW
Advisory Identifier: GHSA-jjxq-ff2g-95vh
CVSS 2.2
CWE-668
Published
Advisory Summary

CVE-2024-51755 is a LOW (CVSS 2.2) twig has unguarded calls to vulnerability (CWE-668: Exposure of Resource to Wrong Sphere) affecting Twig/twig libraries in the Packagist ecosystem. The issue involves twig has unguarded calls to `__isset()` and to array-accesses when the sandbox is enabled. Remediation is available by upgrading affected packages to version 3.11.2, 3.14.1.

CVE-2024-51755 at a Glance

CVE Identifier CVE-2024-51755
GHSA Identifier GHSA-jjxq-ff2g-95vh
Severity LOW
CVSS v3.1 Base Score 2.2
CWE Classification CWE-668: Exposure of Resource to Wrong Sphere
Affected Product Twig/twig
Package Ecosystem Packagist
Published Date
Last Updated

Security Impact

CVSS: 2.2

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

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

How to Fix CVE-2024-51755

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: 3.11.2
Upgrade twig/twig to 3.11.2
twig/twig fixed: 3.14.1
Upgrade twig/twig to 3.14.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 twig/twig

How to Check if You Are Affected

To determine whether your application is affected by CVE-2024-51755, 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 3.11.2), 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-668: Exposure of Resource to Wrong Sphere, where the product exposes a resource to the wrong control sphere, providing unintended actors with inappropriate access to the resource. 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 In a sandbox, and attacker can access attributes of Array-like objects as they were not checked by the security policy. They are now checked via the property policy and the `__isset()` method is now called after the security check. **This is a BC break.** ### Resolution The sandbox mode now ensures access to array-like's properties is allowed. The patch for this issue is available [here](https://github.com/twigphp/Twig/commit/ec39a9dccc5fb4eaaba55e5d79a6f84a8dd8b69d) for the 3.11.x branch, and [here](https://github.com/twigphp/Twig/commit/b957e5a44cc0075d04ccff52f8fa9d8e6db3e3a0) for the 3.x branch. ### Credits We would like to thank Jamie Schouten for reporting the issue and Nicolas Grekas for providing the fix.

CVE-2024-51755 Affected Twig/twig Versions

2 component(s)
Fixed Versions:
3.11.23.14.1
Product / Package Ecosystem Affected Versions Fixed Version
twig/twig
Packagist
< 3.11.2
3.11.2
twig/twig
Packagist
≥ 3.12
< 3.14.1
3.14.1

References

Frequently Asked Questions

What is CVE-2024-51755?
CVE-2024-51755 is a security vulnerability in Twig/twig involving Twig has unguarded calls to `__isset()` and to array-accesses when the sandbox is enabled under CWE-668: Exposure of Resource to Wrong Sphere.
Which Twig/twig versions are affected?
Affected versions include releases prior to 3.11.2, 3.14.1 across affected packages: twig/twig.
What version fixes CVE-2024-51755?
Upgrading to 3.11.2, 3.14.1 (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 3.11.2, 3.14.1. Upgrade your dependency to 3.11.2, 3.14.1 or later.
What is the CVSS score of CVE-2024-51755?
CVE-2024-51755 has a CVSS v3.1 base score of 2.2 (LOW) with vector string CVSS:3.1/AV:N/AC:H/PR:H/UI:N/S:U/C:L/I:N/A:N.
What CWE is associated with CVE-2024-51755?
CVE-2024-51755 is classified under CWE-668: Exposure of Resource to Wrong Sphere (The product exposes a resource to the wrong control sphere, providing unintended actors with inappropriate access to the resource.).
How can I check Packagist dependencies for CVE-2024-51755?
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-jjxq-ff2g-95vh",
  "modified" : "2024-11-12T19:43:00Z",
  "published" : "2024-11-06T19:52:55Z",
  "aliases" : [ "CVE-2024-51755" ],
  "summary" : "Twig has unguarded calls to `__isset()` and to array-accesses when the sandbox is enabled",
  "details" : "### Description\n\nIn a sandbox, and attacker can access attributes of Array-like objects as they were not checked by the security policy.\nThey are now checked via the property policy and the `__isset()` method is now called after the security check.\n**This is a BC break.**\n\n### Resolution\n\nThe sandbox mode now ensures access to array-like's properties is allowed.\n\nThe patch for this issue is available [here](https://github.com/twigphp/Twig/commit/ec39a9dccc5fb4eaaba55e5d79a6f84a8dd8b69d) for the 3.11.x branch, and [here](https://github.com/twigphp/Twig/commit/b957e5a44cc0075d04ccff52f8fa9d8e6db3e3a0) for the 3.x branch.\n\n### Credits\n\nWe would like to thank Jamie Schouten for reporting the issue and Nicolas Grekas for providing the fix.\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:H/UI:N/S:U/C:L/I:N/A:N"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:P/PR:H/UI:N/VC:L/VI:N/VA:N/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "twig/twig"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "3.11.2"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "twig/twig"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "3.12"
      }, {
        "fixed" : "3.14.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/twigphp/Twig/security/advisories/GHSA-jjxq-ff2g-95vh"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-51755"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/twigphp/Twig/commit/831c148e786178e5f2fde9db67266be3bf241c21"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/FriendsOfPHP/security-advisories/blob/master/twig/twig/CVE-2024-51755.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/twigphp/Twig"
  }, {
    "type" : "WEB",
    "url" : "https://symfony.com/blog/unguarded-calls-to-__isset-and-to-array-accesses-when-the-sandbox-is-enabled"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-668" ],
    "severity" : "LOW",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-11-06T19:52:55Z",
    "nvd_published_at" : "2024-11-06T20:15:06Z"
  }
}