GHSA-2q52-x2ff-qgfr
Twig: Possible sandbox bypass when using a source policy
Quick fix
GHSA-2q52-x2ff-qgfr — twig/twig: upgrade to the fixed version with the command below.
composer require twig/twig:^3.26.0Details
# 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.
Are you affected?
Enter the version of the package you're using.
Affected packages
2.16.0No fixed version published yet for twig/twig (composer). Pin to a known-safe version or switch to an alternative.
References
- https://github.com/twigphp/Twig/security/advisories/GHSA-2q52-x2ff-qgfr[WEB]
- https://nvd.nist.gov/vuln/detail/CVE-2026-24425[ADVISORY]
- https://github.com/FriendsOfPHP/security-advisories/blob/master/twig/twig/CVE-2026-24425.yaml[WEB]
- https://github.com/twigphp/Twig[PACKAGE]
- https://github.com/twigphp/Twig/releases/tag/v3.26.0[WEB]
- https://symfony.com/cve-2026-24425[WEB]
- https://www.vulncheck.com/advisories/twig-x-x-sandbox-bypass-via-sourcepolicyinterface[WEB]