CVE-2024-45411: Twig has a possible sandbox bypass
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;
Published Sep 9, 2024 · Updated Oct 10, 2024
Affected packages
twig/twig
- Ecosystem
- Composer (PHP)
- Affected
- >= 1.0.0, < 1.44.8
- Fixed in
- 1.44.8
- Check
composer show twig/twig
twig/twig
- Ecosystem
- Composer (PHP)
- Affected
- >= 2.0.0, < 2.16.1
- Fixed in
- 2.16.1
- Check
composer show twig/twig
twig/twig
- Ecosystem
- Composer (PHP)
- Affected
- >= 3.12.0, < 3.14.0
- Fixed in
- 3.14.0
- Check
composer show twig/twig
twig/twig
- Ecosystem
- Composer (PHP)
- Affected
- >= 3.0.0, < 3.11.1
- Fixed in
- 3.11.1
- Check
composer show twig/twig
Advisory details
From the GitHub Advisory Database (CC BY 4.0).
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 (likeincluded.twig) and not aTemplateorTemplateWrapperinstance; - 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.
Credited to fabpot, stof.
References
- https://github.com/twigphp/Twig/security/advisories/GHSA-6j75-5wfj-gh66
- https://github.com/twigphp/Twig/commit/11f68e2aeb526bfaf638e30d4420d8a710f3f7c6
- https://github.com/twigphp/Twig/commit/2102dd135986db79192d26fb5f5817a566e0a7de
- https://github.com/twigphp/Twig/commit/7afa198603de49d147e90d18062e7b9addcf5233
- https://nvd.nist.gov/vuln/detail/CVE-2024-45411
- https://github.com/twigphp/Twig/commit/41103dcdc2daab4c83cdd05b5b4fde5b7e41e635
- https://github.com/FriendsOfPHP/security-advisories/blob/master/twig/twig/CVE-2024-45411.yaml
- https://symfony.com/blog/twig-security-release-possible-sandbox-bypass
- https://github.com/advisories/GHSA-6j75-5wfj-gh66
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. No analysis has been written for this entry yet. Methodology
More Composer (PHP) vulnerabilities
All Composer (PHP) entriesCVE-2026-49981
Twig: Sandbox filter, tag and function allow-list bypass when sandbox state changes between renders for a cached `Template`
high8.7Jul 1, 2026CVE-2026-48805
Twig: Sandbox state regression in deprecated internal wrappers in `src/Resources/core.php`
lowJun 30, 2026CVE-2026-48806
Twig: Sandbox `__toString()` policy bypass via dynamic mapping keys
mediumJun 30, 2026CVE-2026-48807
Twig: Sandbox `__toString()` policy bypass via `Traversable` in `join` and `replace` filters
mediumJun 30, 2026CVE-2026-48808
Twig: Sandbox property allowlist bypass via the `column` filter under `SourcePolicyInterface`
mediumJun 30, 2026CVE-2026-24425
Twig: Possible sandbox bypass when using a source policy
high8.8No fixJun 5, 2026
