CVE-2026-46639: Sandbox property and method bypass via object-destructuring assignment
Description
The object-destructuring assignment syntax introduced in Twig 3.24.0 generates a call to CoreExtension::getAttribute() with the $sandboxed argument hardcoded to false, regardless of whether a SandboxExtension is active. This permanently disables the sandbox's property and method policy checks for every destructuring expression.
ObjectDestructuringSetBinary::compile() emits:
php CoreExtension::getAttribute($this->env, $this->source, ..., \Twig\Template::ANYCALL, false, false, false, ...); // ^^^^^ // sandbox check never runs
Whereas GetAttrExpression::compile() correctly passes $env->hasExtension(SandboxExtension::class).
An attacker with write access to a sandboxed Twig template can read any public property or invoke any public getter on objects passed to the template engine, bypassing SecurityPolicy restrictions. The exploit requires only the {% do %} tag to be in allowedTags, which is a common configuration.
Resolution
The destructuring compiler now forwards the active sandbox flag to getAttribute() so property/method allowlists are enforced.
Credits
Twig would like to thank Anvil Secure in collaboration with Claude and Anthropic Research for reporting and fixing the issue.
Other sources
Sandbox property and method bypass via object-destructuring assignment
— Packagist
Twig is a template language for PHP. From 3.24.0 until 3.26.0, object-destructuring assignment compiles CoreExtension::getAttribute() with the sandbox argument hardcoded to false, disabling property and method policy checks and allowing an attacker with write access to a sandboxed Twig template to read public properties or invoke public getters on objects passed to the template engine. This issue is fixed in version 3.26.0.
— MITRE
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
composer/twig/twigto a version that resolves this vulnerability.Fixed in 3.26.0 - Upgrade
Upgrade
Twigto a version that resolves this vulnerability.Fixed in 3.26.0
Event History
Frequently Asked Questions
What is the severity of CVE-2026-46639?
The severity of CVE-2026-46639 is rated at risk 65.
How do I fix CVE-2026-46639?
To fix CVE-2026-46639, upgrade to Twig version 3.24.1 or later where the issue is addressed.
What impact does CVE-2026-46639 have on application security?
CVE-2026-46639 can compromise application security by disabling the sandbox's property and method checks.
Which version of Twig introduced the vulnerability represented by CVE-2026-46639?
The vulnerability identified by CVE-2026-46639 was introduced in Twig version 3.24.0.
Is CVE-2026-46639 applicable to older versions of Twig?
CVE-2026-46639 specifically affects Twig versions starting from 3.24.0 onward.