Impact
Twig is a PHP template engine that includes a sandbox mode to restrict which filters, tags, and functions templates may use. The issue arises because the list of approved components is calculated only when a Template instance is constructed and then kept in cache. When an application changes the sandbox policy between renders, the cached Template still references the stale allow‑list, potentially enabling disallowed operations. The vulnerability is classified as CWE‑693 (System Will Not Perform as Intended) and CWE‑863 (Improper Handling of Policy Changes). The primary impact is that code that should be rejected by the sandbox can be executed, allowing an attacker to read or manipulate data outside the sandbox’s intended boundaries.
Affected Systems
All installations of twigphp:Twig older than version 3.27.0 are affected. Any PHP application that caches Template objects and subsequently modifies its sandbox policy between renders is vulnerable. This includes applications that build and cache templates for later use, regardless of how Twig was installed or distributed.
Risk and Exploitability
The CVSS base score of 6 marks the flaw as medium severity. The EPSS score of less than 1 % indicates that exploitation attempts are currently uncommon, and the vulnerability is not listed in the CISA KEV catalog. However, the logic flaw permits a sandbox bypass that could lead to arbitrary code execution. Based on the description, it is inferred that the most likely attack vector involves an application that re‑renders cached templates after changing its sandbox policy without clearing the cache. Such a scenario provides the conditions necessary for the bypass, making timely mitigation important.
OpenCVE Enrichment
Github GHSA