CVE-2026-24425: Twig Remote Code Execution Vulnerability

HIGH
Advisory Identifier: GHSA-2q52-x2ff-qgfr
CVSS 8.8
CWE-693
Published
Advisory Summary

CVE-2026-24425 is a HIGH (CVSS 8.8) remote code execution vulnerability (CWE-693: Protection Mechanism Failure) affecting Twig libraries in the Packagist ecosystem. The issue involves possible sandbox bypass when using a source policy. Remediation is available by upgrading affected packages to version 3.26.0.

CVE-2026-24425 at a Glance

CVE Identifier CVE-2026-24425
GHSA Identifier GHSA-2q52-x2ff-qgfr
Severity HIGH
CVSS v3.1 Base Score 8.8
CWE Classification CWE-693: Protection Mechanism Failure
Affected Product 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-2026-24425

To remediate this vulnerability, upgrade all affected 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: Latest secure release
Upgrade twig/twig to Latest secure release
twig/twig fixed: 3.26.0
Upgrade twig/twig to 3.26.0
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-2026-24425, inspect your project dependencies for Twig:

inspect dependencies for twig/twig

Analyze the terminal output to locate any version of Twig in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.26.0), 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, 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 using the sandbox with a `SourcePolicyInterface`, Twig does not always apply the sandbox restriction that forbids non-`Closure` callbacks for callback-accepting filters. The issue affects the `sort`, `filter`, `map`, and `reduce` filters. In the affected versions, the runtime check that rejects non-`Closure` callbacks in sandbox mode does not use the current template `Source`. As a result, when the sandbox is enabled through a source policy instead of being enabled globally, Twig can incorrectly treat the current execution as non-sandboxed for these callback checks. This can allow user-controlled templates to pass arbitrary PHP callables to callback-accepting filters even though the template is being sandboxed through a source policy. The issue happens when all these conditions are met: - The sandbox is not enabled globally; - A `SourcePolicyInterface` enables the sandbox for the rendered template; - The template uses one of the `sort`, `filter`, `map`, or `reduce` filters; - The callback is not a `Closure`. # Resolution The patch makes callback sandbox checks source-aware by propagating the current template `Source` to callback-accepting filters and using it when deciding whether sandbox restrictions apply. # Credits We would like to thank XavLim and Wade Sparks for reporting the issue and Fabien Potencier for fixing the issue.

CVE-2026-24425 Affected Twig Versions

2 component(s)
Fixed Versions:
3.26.0
Product / Package Ecosystem Affected Versions Fixed Version
twig/twig
Packagist
≥ 2.16.0
≤ 2.16.1
twig/twig
Packagist
≥ 3.9.0
< 3.26.0
3.26.0

References

Frequently Asked Questions

What is CVE-2026-24425?
CVE-2026-24425 is a security vulnerability in Twig involving Possible sandbox bypass when using a source policy under CWE-693: Protection Mechanism Failure.
Which Twig versions are affected?
Affected versions include releases prior to 3.26.0 across affected packages: twig/twig.
What version fixes CVE-2026-24425?
Upgrading to 3.26.0 (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 Latest secure release, 3.26.0. Upgrade your dependency to Latest secure release, 3.26.0 or later.
What is the CVSS score of CVE-2026-24425?
CVE-2026-24425 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-2026-24425?
CVE-2026-24425 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-2026-24425?
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-2q52-x2ff-qgfr",
  "modified" : "2026-06-05T20:41:33Z",
  "published" : "2026-06-05T20:41:33Z",
  "aliases" : [ "CVE-2026-24425" ],
  "summary" : "Twig: Possible sandbox bypass when using a source policy",
  "details" : "# Description\n\nWhen using the sandbox with a `SourcePolicyInterface`, Twig does not always apply the sandbox restriction that forbids non-`Closure` callbacks for callback-accepting filters.\n\nThe issue affects the `sort`, `filter`, `map`, and `reduce` filters.\n\nIn the affected versions, the runtime check that rejects non-`Closure` callbacks in sandbox mode does not use the current template `Source`. As a result, when the sandbox is enabled through a source policy instead of being enabled globally, Twig can incorrectly treat the current execution as non-sandboxed for these callback checks.\n\nThis can allow user-controlled templates to pass arbitrary PHP callables to callback-accepting filters even though the template is being sandboxed through a source policy.\n\nThe issue happens when all these conditions are met:\n\n- The sandbox is not enabled globally;\n- A `SourcePolicyInterface` enables the sandbox for the rendered template;\n- The template uses one of the `sort`, `filter`, `map`, or `reduce` filters;\n- The callback is not a `Closure`.\n\n# Resolution\n\nThe patch makes callback sandbox checks source-aware by propagating the current template `Source` to callback-accepting filters and using it when deciding whether sandbox restrictions apply.\n\n# Credits\n\nWe would like to thank XavLim and Wade Sparks for reporting the issue and Fabien Potencier for fixing the issue.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "twig/twig"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.16.0"
      }, {
        "last_affected" : "2.16.1"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "twig/twig"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "3.9.0"
      }, {
        "fixed" : "3.26.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/twigphp/Twig/security/advisories/GHSA-2q52-x2ff-qgfr"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-24425"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/FriendsOfPHP/security-advisories/blob/master/twig/twig/CVE-2026-24425.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/twigphp/Twig"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/twigphp/Twig/releases/tag/v3.26.0"
  }, {
    "type" : "WEB",
    "url" : "https://symfony.com/cve-2026-24425"
  }, {
    "type" : "WEB",
    "url" : "https://www.vulncheck.com/advisories/twig-x-x-sandbox-bypass-via-sourcepolicyinterface"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-693" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-06-05T20:41:33Z",
    "nvd_published_at" : "2026-05-20T14:16:38Z"
  }
}