Vulnerability GHSA-7p85-w9px-jpjp

Critical
CRITICAL RISK
CVSS Score: 9.8
Score Range: 9.0–10.0
Critical severity vulnerabilities (CVSS 9.0–10.0). These represent the highest impact issues.
5 months ago
May 21, 2026 at 09:24 PM UTC
Twig: PHP code injection via `{% use %}` template name
1.15.1 - 3.25.0
1.15.1 - 3.25.0

Summary

Twig: PHP code injection via `{% use %}` template name

Details

Description

Compiler::string() escapes ", $, \, NUL and TAB when generating PHP double-quoted string literals, but does not escape single quotes. In ModuleNode::compileConstructor(), the template name from a {% use %} tag is compiled via subcompile() -> string() and placed inside a surrounding PHP single-quoted string literal. A template name containing a single quote terminates that surrounding string early, allowing arbitrary PHP expressions to be injected into the compiled cache file.

The injected code executes within the PHP process when the cache file is first loaded, bypassing the Twig sandbox entirely and achieving remote code execution. SecurityPolicy unconditionally allows {% use %} regardless of the configured allowedTags, so this primitive is reachable from sandboxed templates as well.

Resolution

Compiler::string() now also escapes single quotes so that template names placed inside single-quoted PHP literals can no longer break out of the surrounding context.

Credits

Twig would like to thank Anvil Secure in collaboration with Claude and Anthropic Research for reporting the issue and providing the fix.

Impacted packages

Timeline

Published
5 months ago
May 21, 2026 at 09:24 PM UTC
Fixed (3.26.0)
5 months ago
May 20, 2026 at 07:31 AM UTC
Last Modified
10 hours ago
November 04, 2026 at 12:15 AM UTC