CVE-2026-24425 is a high severity (CVSS 8.8) sandbox bypass in the Twig template engine. It affects 2.16.x and 3.9.0 up to but not including 3.26.0, when the sandbox is enabled through a SourcePolicyInterface. Upgrade to Twig 3.26.0, and review who can supply templates.
What's affected
GitHub's advisory lists the Composer package twig/twig with affected versions 2.16.* and 3.9.0 up to before 3.26.0. The patched version is 3.26.0.
Not every Twig user is affected. The advisory says the issue appears only when all four conditions are true: the sandbox is not enabled globally, a SourcePolicyInterface enables the sandbox for the rendered template, the template uses the sort, filter, map or reduce filters, and the callback passed is not a Closure.
So the people at risk are those who let users supply templates and sandbox those templates through a source policy.
How to check if you're exposed
Check the installed version:
composer show twig/twig
Then check whether you enable the sandbox through a source policy:
grep -rn "SourcePolicyInterface" src/ config/
If you do not render user supplied templates, or you enable the sandbox globally, the conditions in the advisory are not met. Check vendor code and framework bundles too, since they can use Twig on your behalf.
For a quick look at your own dependencies, Safeguard's free in-browser dependency scan at https://gold.safeguard.sh/scan checks them against known CVEs in your browser.
What to do now
- Upgrade twig/twig to 3.26.0 or later with Composer.
- Run your template tests after the upgrade.
- If you let users author templates, review what that feature allows and whether it is needed.
- If you cannot upgrade yet, consider enabling the sandbox globally for user templates, since the advisory's conditions require it to be off.
- Rebuild and redeploy your application image or release.
Why it matters
The record classifies this as CWE-693, protection mechanism failure. A sandbox is a promise that untrusted template code can only do a limited set of things. Here, a runtime check that should reject non-Closure callbacks did not use the current template source, so it treated a sandboxed template as unsandboxed. VulnCheck's description says this can lead to arbitrary code execution.
The scope is narrow but serious. A template system that is meant to let customers customize emails or pages is the typical case, and a bypass turns customization into code execution on the server. The CVE is not in CISA's Known Exploited Vulnerabilities catalog.
Finding template sandboxes in your own code
A version check tells you whether Twig is old. It does not tell you whether the conditions in the advisory can happen in your application. Those take a few minutes to look at, and the answers are worth writing down.
Start with where templates come from. Templates that live in your repository and ship with a release are trusted code. Templates that customers, editors or plugins can write are user input. The sandbox exists only for the second kind. List every feature where someone outside your engineering team can author or edit a template, such as email layouts, report builders, page editors and notification texts.
Next, find out how the sandbox is switched on. The advisory describes two modes: enabled globally, or enabled for chosen templates through a source policy. Search your code for the policy interface and read what the policy returns. If it returns true for templates that users write, you are in the situation the advisory describes.
Then look at which filters those templates can reach. The advisory names sort, filter, map and reduce. Check your sandbox security policy, which lists the allowed tags, filters and functions. If those four filters are not allowed for user templates, the described path is closed even before you upgrade. Do not rely on that alone, since policies drift.
Hardening beyond the upgrade
Treat the sandbox as one layer. Run template rendering for untrusted authors in a process with low privileges and no access to secrets. Keep template authoring behind roles, and log who changed which template. Review the allowed filter and function list now and then, and remove what nobody needs.
Finally, pin twig/twig in your lockfile and let your dependency checks flag the affected ranges, 2.16.x and 3.9.0 to 3.25.x, so a stale copy in a second project does not slip through.
Try it yourself
Click through it at your own pace, or open it full screen.
Quick check
Am I affected if I use Twig only with my own templates?
The advisory's conditions center on a sandbox enabled by a source policy for rendered templates. If you only render your own trusted templates, you are unlikely to meet them, but upgrading is still sensible.
Which version fixes it?
Twig 3.26.0.
Sources
Last reviewed: 19 October 2026.