CVE-2026-24425: Twig Sandbox Bypass Vulnerability
Twig versions 2.16.x and 3.9.0 through 3.25.x contain a sandbox bypass vulnerability (CVE-2026-24425) when using a SourcePolicyInterface, allowing attackers to pass arbitrary PHP callables and execute arbitrary code when the sandbox is enabled through a source policy rather than globally.
Twig, a flexible template engine for PHP, is susceptible to a sandbox bypass vulnerability identified as CVE-2026-24425. This flaw affects versions 2.16.x and 3.9.0 through 3.25.x. The vulnerability resides within the SourcePolicyInterface, which is intended to enforce security restrictions on template execution. However, a flaw in the runtime check allows attackers with template rendering capabilities to circumvent these restrictions. Specifically, attackers can pass arbitrary PHP callables to sort, filter, map, and reduce filters, leading to arbitrary code execution if the sandbox is enabled via a source policy. This bypass occurs because the runtime check fails to use the current template source, allowing malicious code to be injected and executed.
Attack Chain
- An attacker gains the ability to render Twig templates, often through a web application vulnerability such as template injection.
- The application uses a SourcePolicyInterface to enable a security sandbox for Twig templates.
- The attacker crafts a malicious Twig template that leverages the
sort,filter,map, orreducefilters. - Within these filters, the attacker provides an arbitrary PHP callable function.
- The vulnerable runtime check fails to properly validate the source of the template.
- The arbitrary PHP callable is executed without proper sandbox restrictions.
- The attacker achieves arbitrary code execution on the server.
Impact
Successful exploitation of this vulnerability allows attackers with template rendering capabilities to bypass the intended security sandbox and execute arbitrary code on the server. This can lead to complete system compromise, data theft, or denial of service. While the specific number of affected installations is unknown, any application using Twig within the specified version range and relying on SourcePolicyInterface for sandboxing is potentially vulnerable.
Recommendation
- Upgrade Twig to version 3.26.0 or later, which contains a fix for CVE-2026-24425.
- If upgrading is not immediately feasible, avoid using SourcePolicyInterface for sandboxing and rely on global sandbox settings instead.
- Monitor web server logs for suspicious activity related to template rendering, particularly the use of
sort,filter,map, andreducefilters. - Deploy the Sigma rule “Detect Twig Sandbox Bypass Attempt via PHP Callable” to identify potential exploitation attempts in web server logs.
Detection coverage 2
Detect Twig Sandbox Bypass Attempt via PHP Callable
highDetects CVE-2026-24425 exploitation — an attempt to bypass the Twig sandbox by using a PHP callable function within Twig template filters.
Detect Twig SourcePolicyInterface Usage
infoDetects usage of SourcePolicyInterface which is required to exploit CVE-2026-24425
Detection queries are available on the platform. Get full rules →