8.7high
Twig 2.16.x & 3.9.0-3.25.x Sandbox Bypass via SourcePolicyInterface
- Severity
- 8.7high CVSS:4.0 by VulnCheck
- Exploit likelihood
- 0.76% (higher than 56% of CVEs; EPSS, by FIRST)
- Published
- Last changed
- Assigned by
- VulnCheck
- Also known as
- GHSA-2q52-x2ff-qgfr
Description
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.
Affected
| Product or package | Versions | Reported by |
|---|---|---|
| twigphp Twig | from 3.9.0 before 3.26.0, 2.16.0 | CVE List |
| twig/twig (Packagist) | from 2.16.0 up to 2.16.1, from 3.9.0 before 3.26.0 | GitHub Advisory Database |
| symfony twig | from 2.16.0 up to 2.16.1, from 3.9.0 before 3.26.0 | NVD |
All scores
| VulnCheck | 8.7high CVSS:4.0 | 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 |
| VulnCheck | 8.8high CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H |
| GitHub | 8.8high CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H |
| GitHub | high CVSS:4.0 | 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 |
| NVD | 9.9critical CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H |
Classification
SSVC (CISA-ADP): exploitation none, automatable no, technical impact total.
What each source says
CVE List
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.
GitHub Advisory Database
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
SourcePolicyInterfaceenables the sandbox for the rendered template; - The template uses one of the
sort,filter,map, orreducefilters; - 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.
NVD (es)
Versiones de Twig 2.16.x y 3.9.0 hasta 3.25.x contienen una vulnerabilidad de bypass de sandbox al usar una SourcePolicyInterface que permite a atacantes con capacidades de renderizado de plantillas pasar callables PHP arbitrarios a los filtros sort, filter, map y reduce. Los atacantes pueden explotar la verificación en tiempo de ejecución que no utiliza la fuente de plantilla actual para eludir las restricciones de sandbox y ejecutar código arbitrario cuando el sandbox está habilitado a través de una política de fuente en lugar de globalmente.
References
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2026-24425 changed 2026-11-17 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-2q52-x2ff-qgfr changed 2026-09-10 | CC-BY-4.0 |
| NVD | CVE-2026-24425 changed 2026-11-17 | Public domain |