Impact
Twig's sandbox feature is designed to limit which methods can be called on objects within templates. Prior to version 3.27.0 the checkMethodAllowed routine automatically permitted all public methods of Twig\\Markup instances, regardless of the allowedMethods whitelist. Because Twig\\Markup is not a final class, any subclass inherits this behavior. If an application passes a Markup-derived object into a sandboxed template, the template author can invoke any public method defined by that subclass. This bypass allows arbitrary code execution through the sandbox, elevating the impact from a limited template interference to full execution of methods on the subclass, potentially revealing sensitive data or executing privileged operations.
Affected Systems
Twig versions 1.0.0 through 3.26.x, distributed by the twigphp project, are affected. The vulnerability is present in all releases prior to 3.27.0. Upgrading to Twig 3.27.0 or newer resolves the issue.
Risk and Exploitability
The CVSS score of 8.7 marks this as a high‑severity flaw. No EPSS data is available, so the likelihood of exploitation is unclear, and it is not yet listed in the CISA KEV catalog. The likely attack vector is a sandboxed template that an attacker can influence – for example, through a content management system that renders user‑supplied templates. If such a template is rendered while a Markup‑derived object is in scope, the attacker can trigger any public method on that object, which can lead to data exposure or remote code execution. The flaw requires an application to supply a Markup subclass to the template; therefore, detecting and limiting such objects mitigates the risk.
OpenCVE Enrichment
Debian DSA