Twig security release: Possible sandbox bypass
September 9, 2024 • Published by Fabien Potencier
Affected Versions
Twig >1.0.0,<=1.44.7 || >2.0.0,<=2.16.0 || >3.0.0,<=3.11.0 || >=3.12.0,<3.14.0 versions are affected by this security issue.
Even if twig 1.x and 2.x are not maintained anymore, we've released new versions with the security fix.
This issue has been fixed in Twig 1.44.8, 2.16.1, and 3.14.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 aTemplate
orTemplateWrapper
instance; - 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.
Manage your notification preferences to receive an email as soon as a Symfony security release is published.
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.