CVE-2026-24425: Twig 2.16.x & 3.9.0-3.25.x Sandbox Bypass via SourcePolicyInterface

Published May 20, 2026
·
Updated

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.

Other sources

Twig versions 2.16.x and 3.9.0 through 3.25.x contain a sandbox bypass vulnerability when using a SourcePolicyInterface that allows attackers with template rendering capabilities to pass arbitrary PHP callables to sort, filter, map, and reduce filters. Attackers can exploit the runtime check that fails to use the current template source to bypass sandbox restrictions and execute arbitrary code when the sandbox is enabled through a source policy rather than globally.

MITRE

Affected Software

7 affected componentsFixes available
packagist/twig/twig>=2.16.0<2.17.0, >=3.9.0<3.26.0
Symfony Twig>=2.16.0<=2.16.1
Symfony Twig>=3.9.0<3.26.0
composer/twig/twig>=3.9.0<3.26.0
3.26.0
composer/twig/twig>=2.16.0<=2.16.1
debian/php-twig<=3.20.0-2
2.14.3-1+deb11u22.14.3-1+deb11u43.5.1-1+deb12u13.5.1-1+deb12u33.27.0-0+deb13u13.27.1-1
IBM API Connect V12 OnPrem<=All

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade composer/twig/twig to a version that resolves this vulnerability.

    Fixed in 3.26.0
  2. Upgrade

    Upgrade debian/php-twig to a version that resolves this vulnerability.

    Fixed in 2.14.3-1+deb11u2Fixed in 2.14.3-1+deb11u4Fixed in 3.5.1-1+deb12u1Fixed in 3.5.1-1+deb12u3Fixed in 3.27.0-0+deb13u1Fixed in 3.27.1-1
  3. Upgrade

    Upgrade twig/twig to a version that resolves this vulnerability.

    Fixed in 3.9.0-3.25.x
  4. Upgrade

    Upgrade twig/twig to a version that resolves this vulnerability.

    Fixed in 2.16.x
  5. Compensating control

    If you use Twig sandbox with a SourcePolicyInterface, ensure that templates cannot provide arbitrary user-controlled PHP callables to the callback-accepting filters sort, filter, map, and reduce (e.g., restrict what templates can do / control template inputs and available callables).

Event History

May 20, 2026
CVE Published
via MITRE·01:45 PM
Data Sourced
via MITRE·01:45 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·02:16 PM
DescriptionSeverityWeaknessAffected Software
Jun 5, 2026
Advisory Published
via GitHub·08:41 PM
Data Sourced
via GitHub·08:41 PM
DescriptionSeverityWeaknessAffected Software
Jun 8, 2026
Data Sourced
via Ubuntu·09:05 PM
RemedyDescriptionSeverityAffected Software
Data Sourced
via Debian·09:06 PM
DescriptionAffected Software
Data Sourced
via Launchpad·09:06 PM
Description
Jul 7, 2026
Data Sourced
via IBM·12:00 AM
DescriptionAffected Software

Parent advisories

This vulnerability appears in the following advisories.

Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of CVE-2026-24425?

CVE-2026-24425 has a medium severity rating due to the potential for attackers to execute arbitrary PHP callables within specified Twig versions.

2

How do I fix CVE-2026-24425?

To fix CVE-2026-24425, upgrade to Twig version 2.17.0 or later, or 3.26.0 or later.

3

What versions are affected by CVE-2026-24425?

CVE-2026-24425 affects Twig versions from 2.16.0 to less than 2.17.0 and from 3.9.0 to less than 3.26.0.

4

Who is impacted by CVE-2026-24425?

Developers and applications using affected versions of Twig are at risk of exploitation due to sandbox bypass vulnerabilities.

5

What are the potential risks of CVE-2026-24425?

The potential risks include unauthorized access and the ability for attackers to execute malicious PHP code via template rendering capabilities.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203