Skip to main content
Mallory
Unrated

Twig sandbox bypass and PHP code injection via _self dynamic attribute macro reference

IdentifiersCVE-2026-46640CWE-94

CVE-2026-46640 is a critical Twig sandbox bypass in the PHP template engine affecting dynamic attribute compilation for the obj.(expr) syntax introduced in Twig 3.15.0. When the receiver is _self and the dynamic attribute expression is a string literal, Twig's parser/compiler takes a macro-reference path that short-circuits normal validation. In the vulnerable flow, a user-controlled string is concatenated into a macro reference name and emitted into generated PHP source without proper validation/escaping. As a result, an attacker who can supply Twig template source can inject arbitrary PHP into the compiled template. The injected code can execute during template load/compilation before checkSecurity() is enforced, resulting in a complete escape from SandboxExtension protections.

Share:
For your environment

Are you exposed to this one?

Mallory correlates every CVE against your assets, your vendors, and active adversary campaigns. Know which vulnerabilities matter for you, not just which ones are loud.

ANALYST BRIEF

Impact, mitigation & remediation

What it means. What to do now. Patch path, mitigations, and the assume-compromise checklist.

Impact

What an attacker gets, and what they’ve been doing with it.

Successful exploitation enables arbitrary PHP code execution on the host running Twig. Because the injected PHP is emitted into the compiled template and can run before sandbox security checks, the vulnerability defeats configured sandbox restrictions, including globally enabled sandbox configurations and restrictive or empty SecurityPolicy allowlists. This can lead to full application compromise, access to sensitive data available to the PHP process, server-side command execution, persistence, and follow-on lateral movement depending on the privileges of the web/application runtime.

Mitigation

If you can’t patch tonight, do this now.

If immediate patching is not possible, prevent untrusted users from supplying or modifying Twig template source, especially in sandboxed or multi-tenant use cases. Avoid exposing the vulnerable _self.(...) dynamic-attribute macro-reference behavior to attacker-controlled input. Review applications for any feature that renders user-provided Twig templates or fragments, and disable or isolate such functionality until patched. No complete workaround was provided by the vendor.

Remediation

Patch, then assume compromise.

Upgrade Twig to version 3.26.0 or later, which adds stricter validation for dynamic attributes resolving to macro identifiers and ensures macro-reference compilation uses a properly escaped/validated path. If consuming distribution packages, apply the vendor backport or security update; for Debian stable (trixie), upgrade php-twig to 3.27.0-0+deb13u1 or later as referenced in the advisory.
PUBLIC EXPLOITS

Exploits

No public exploits tracked yet. Mallory keeps watching.

VALID 0 / 0 TOTALView more in app

No public exploit code observed for this vulnerability.

What this page doesn’t show

The version that knows your environment.

This page is what’s public. Mallory adds the parts that aren’t: which of your assets are affected, which adversaries are exploiting it right now, which detections to deploy, and what to do tonight.
Exposure mapping

Query your assets running an affected version, and investigate the blast radius.

Threat actor evidence

Every observed campaign linking this CVE to a named adversary.

Associated malware

Malware families riding this exploit, with evidence and IOCs.

Detection signatures

YARA, Sigma, Snort, and vendor rules, auto-deployed to your SIEM.

Vendor-by-vendor mapping

Cross-references every affected SKU, including bundled OEM variants.

Social activity9

Community discussion across Reddit, Mastodon, and other social sources.