CVE-2024-45411: Twig/twig Twig Has A Possible Sandbox Vulnerability

MODERATE
Advisory Identifier: GHSA-6j75-5wfj-gh66
CVSS 8.5
CWE-693
Published
Advisory Summary

CVE-2024-45411 is a MODERATE (CVSS 8.5) twig has a possible sandbox vulnerability (CWE-693: Protection Mechanism Failure) affecting Twig/twig libraries in the Packagist ecosystem. The issue involves twig has a possible sandbox bypass. Remediation is available by upgrading affected packages to version 1.44.8, 2.16.1, 3.14.0, 3.11.1.

CVE-2024-45411 at a Glance

CVE Identifier CVE-2024-45411
GHSA Identifier GHSA-6j75-5wfj-gh66
Severity MODERATE
CVSS v3.1 Base Score 8.5
CWE Classification CWE-693: Protection Mechanism Failure
Affected Product Twig/twig
Package Ecosystem Packagist
Published Date
Last Updated

Security Impact

CVSS: 8.5

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

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

How to Fix CVE-2024-45411

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: 1.44.8
Upgrade twig/twig to 1.44.8
twig/twig fixed: 2.16.1
Upgrade twig/twig to 2.16.1
twig/twig fixed: 3.14.0
Upgrade twig/twig to 3.14.0
twig/twig fixed: 3.11.1
Upgrade twig/twig to 3.11.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-45411, 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 1.44.8), 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-693: Protection Mechanism Failure, where the product does not use or incorrectly uses a protection mechanism that provides sufficient defense against directed attacks against the product. 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 Under some circumstances, the sandbox security checks are not run which allows user-contributed templates to bypass the sandbox restrictions. The security issue happens when all these conditions are met: * The sandbox is disabled globally; * The sandbox is enabled via a sandboxed `include()` function which references a template name (like `included.twig`) and not a `Template` or `TemplateWrapper` instance; * The included template has been loaded before the `include()` call but in a non-sandbox context (possible as the sandbox has been globally disabled). ### Resolution The patch ensures that the sandbox security checks are always run at runtime. ### Credits We would like to thank Fabien Potencier for reporting and fixing the issue.

CVE-2024-45411 Affected Twig/twig Versions

4 component(s)
Fixed Versions:
1.44.82.16.13.14.03.11.1
Product / Package Ecosystem Affected Versions Fixed Version
twig/twig
Packagist
≥ 1.0.0
< 1.44.8
1.44.8
twig/twig
Packagist
≥ 2.0.0
< 2.16.1
2.16.1
twig/twig
Packagist
≥ 3.12.0
< 3.14.0
3.14.0
twig/twig
Packagist
≥ 3.0.0
< 3.11.1
3.11.1

References

Frequently Asked Questions

What is CVE-2024-45411?
CVE-2024-45411 is a security vulnerability in Twig/twig involving Twig has a possible sandbox bypass under CWE-693: Protection Mechanism Failure.
Which Twig/twig versions are affected?
Affected versions include releases prior to 1.44.8, 2.16.1, 3.14.0, 3.11.1 across affected packages: twig/twig.
What version fixes CVE-2024-45411?
Upgrading to 1.44.8, 2.16.1, 3.14.0, 3.11.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 1.44.8, 2.16.1, 3.14.0, 3.11.1. Upgrade your dependency to 1.44.8, 2.16.1, 3.14.0, 3.11.1 or later.
What is the CVSS score of CVE-2024-45411?
CVE-2024-45411 has a CVSS v3.1 base score of 8.5 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:H.
What CWE is associated with CVE-2024-45411?
CVE-2024-45411 is classified under CWE-693: Protection Mechanism Failure (The product does not use or incorrectly uses a protection mechanism that provides sufficient defense against directed attacks against the product.).
How can I check Packagist dependencies for CVE-2024-45411?
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-6j75-5wfj-gh66",
  "modified" : "2024-10-10T14:50:22Z",
  "published" : "2024-09-09T20:19:26Z",
  "aliases" : [ "CVE-2024-45411" ],
  "summary" : "Twig has a possible sandbox bypass",
  "details" : "### Description\n\nUnder some circumstances, the sandbox security checks are not run which allows user-contributed templates to bypass the sandbox restrictions.\n\nThe security issue happens when all these conditions are met:\n\n * The sandbox is disabled globally;\n * The sandbox is enabled via a sandboxed `include()` function which references a template name (like `included.twig`) and not a `Template` or `TemplateWrapper` instance;\n * The included template has been loaded before the `include()` call but in a non-sandbox context (possible as the sandbox has been globally disabled).\n\n### Resolution\n\nThe patch ensures that the sandbox security checks are always run at runtime.\n\n### Credits\n\nWe would like to thank Fabien Potencier for reporting and fixing the issue.\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:P/PR:L/UI:N/VC:N/VI:N/VA:N/SC:H/SI:H/SA:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "twig/twig"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "1.0.0"
      }, {
        "fixed" : "1.44.8"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "twig/twig"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.0.0"
      }, {
        "fixed" : "2.16.1"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "twig/twig"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "3.12.0"
      }, {
        "fixed" : "3.14.0"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "twig/twig"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "3.0.0"
      }, {
        "fixed" : "3.11.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/twigphp/Twig/security/advisories/GHSA-6j75-5wfj-gh66"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-45411"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/twigphp/Twig/commit/11f68e2aeb526bfaf638e30d4420d8a710f3f7c6"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/twigphp/Twig/commit/2102dd135986db79192d26fb5f5817a566e0a7de"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/twigphp/Twig/commit/41103dcdc2daab4c83cdd05b5b4fde5b7e41e635"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/twigphp/Twig/commit/7afa198603de49d147e90d18062e7b9addcf5233"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/FriendsOfPHP/security-advisories/blob/master/twig/twig/CVE-2024-45411.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/twigphp/Twig"
  }, {
    "type" : "WEB",
    "url" : "https://symfony.com/blog/twig-security-release-possible-sandbox-bypass"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-693" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-09-09T20:19:26Z",
    "nvd_published_at" : "2024-09-09T19:15:13Z"
  }
}