Aug 7, 2026·6 min read·0 visits
Authenticated control panel users can escape the Twig template sandbox in Craft CMS by calling the inherited 'attachBehavior' method on allowed Element objects, leading to arbitrary PHP class instantiation and remote command execution on the server.
An authenticated remote code execution vulnerability exists in Craft CMS due to a flaw in how the Twig template sandbox policy handles class-level allowlists. Prior to the fix, the security policy allowed arbitrary public methods from parent classes of allowed interfaces, allowing authenticated attackers to invoke Yii component methods such as attachBehavior on element models to load arbitrary classes and execute system commands.
Craft CMS relies on the Twig template engine to render dynamic views and user-customizable content securely. To protect the underlying server, Craft CMS provides an optional Twig sandbox capability using the enableTwigSandbox() configuration. This sandbox restricts access to unsafe PHP classes, functions, properties, and methods, ensuring that template authors operate within a safe subset of APIs.
The vulnerability identified as GHSA-F5WM-88JV-G5HX represents a breakdown of this sandbox boundary. A flaw in the custom SecurityPolicy class allowed administrative users with template customization privileges to bypass class and method restrictions entirely. By executing arbitrary PHP logic within the template environment, an authenticated attacker can achieve remote code execution.
The core of the issue lies in how the application manages permissions for classes implementing the ElementInterface. Because Craft CMS trusted entire interfaces at a class level, any subclass inheriting from these interfaces was granted access to its entire object hierarchy. This exposed low-level framework capabilities from the underlying Yii Framework to the sandbox engine.
The sandbox implementation in Craft CMS utilizes the SecurityPolicy class to enforce access controls during template compilation and execution. When rendering a template, Twig queries the security policy's checkMethodAllowed($obj, $method) and checkPropertyAllowed($obj, $property) methods. These checks confirm whether the targeted object and its called method are explicitly allowed by configuration or decorator attributes.
Prior to the patch, the security policy evaluated object eligibility based on whether the class or one of its implemented interfaces carried the #[AllowedInSandbox] attribute. Once an interface was labeled with this attribute, the policy permitted access to any public method on any object implementing that interface. It failed to restrict method access strictly to those defined by the allowed interface itself.
The critical failure occurs with ElementInterface, which was annotated with #[AllowedInSandbox]. Every major content class in Craft CMS, such as Entry, User, Asset, and Category, implements this interface. Because these models inherit from the base Element class, they also inherit from yii\base\Component, a foundational class in the Yii Framework.
As a consequence of the class-level allowlisting model, the Twig sandbox permitted execution of all public methods belonging to yii\base\Component on any active Element instance. This exposed the dynamic attachBehavior($name, $behavior) method to the sandboxed environment. This specific method acts as a class-loading utility that instantiates arbitrary PHP classes when supplied with a configuration array.
The vulnerability was patched by transitioning from a broad class-level trust model to a strict, granular method-level verification strategy. In the vulnerable implementation, the SecurityPolicy class relied on class-level checks that allowed any inherited method of an allowed object. The fix introduces a new contract, craft\web\twig\AllowableInSandbox, which requires classes to explicitly validate their own exposed methods.
The following diagram illustrates the vulnerable inheritance chain and how Yii's framework mechanisms were exposed through the sandbox:
The patch removed the #[AllowedInSandbox] attribute from ElementInterface and altered SecurityPolicy.php to delegate checks to the target object.
// Patched implementation in craft/web/twig/SecurityPolicy.php
public function checkMethodAllowed($obj, $method): void
{
if ($obj instanceof AllowableInSandbox && $obj->methodAllowedInSandbox($method)) {
return;
}
// ... original checks continue ...
}The base Element class now implements AllowableInSandbox and enforces strict controls over which methods can run. By default, it returns false for arbitrary method calls, completely blocking inherited parent methods.
// Patched implementation in craft/base/Element.php
abstract class Element extends Component implements ElementInterface, AllowableInSandbox
{
public function methodAllowedInSandbox(string $method): bool
{
// Disallow all methods by default unless explicitly permitted
return false;
}
public function propertyAllowedInSandbox(string $property): bool
{
// Explicitly allow only safe dynamic properties like field handles
if ($this->hasEagerLoadedElements($property) || $this->fieldByHandle($property) !== null) {
return true;
}
return false;
}
}To exploit this vulnerability, an attacker must have administrative or editor access to the Craft CMS control panel with permissions to modify templates that are rendered in a sandboxed context. The target template must have access to a variable representing a Craft Element, such as an entry object, which is standard in many CMS configurations.
The attacker injects a malicious Twig payload designed to invoke the attachBehavior method on the exposed element. The method accepts a behavior configuration array. When the second argument is an array, Yii’s underlying dependency injection engine invokes Yii::createObject() to resolve and hydrate the class specified by the class key.
The attacker selects a behavior class that provides a callback hook capable of running system functions. A common target is yii\behaviors\AttributeTypecastBehavior. By structuring the behavior to map typecasting events to an executable system process class, such as Psy\Readline\Hoa\ConsoleProcessus, the attacker configures an execution path.
Once the behavior is attached, the attacker triggers the associated event callback within the template. When the template calls the trigger() method with the targeted event name, the application processes the behavior chain. This evaluates the payload and executes the arbitrary command string on the hosting operating system, running with the privileges of the web server user.
The impact of GHSA-F5WM-88JV-G5HX is critical, representing complete administrative takeover of the hosting server environment. Successful exploitation grants the attacker the ability to execute arbitrary operating system commands. This execution bypasses all application-layer security boundaries, data separation controls, and database user limitations.
With remote command execution capabilities, the attacker can access sensitive environment variables, read database credentials from configurations, and exfiltrate database contents. The attacker can also write malicious scripts to the web root, establishing persistent web shells for long-term access. This enables lateral movement within the hosting network or infrastructure.
Because the vulnerability requires authenticated access, the risk is slightly mitigated compared to unauthenticated RCE exploits. However, inside threats, compromised low-privileged administrator credentials, or cross-site scripting (XSS) attacks targeting administrators can still serve as vectors to trigger this exploit. The severity remains high due to the absolute compromise of system integrity.
The primary remediation strategy is upgrading the Craft CMS installation to a patched version. The maintainers have released updates that address this vulnerability by implementing strict sandbox validation routines. Users on the 4.x branch must upgrade to version 4.18.3 or higher, while users on the 5.x branch must upgrade to version 5.10.7 or higher.
If an immediate upgrade is not feasible, administrators must implement mitigation steps to minimize the attack surface. Access to template editing capabilities within the control panel should be strictly revoked for all non-essential administrative accounts. This limits the exposure of sandboxed template rendering endpoints to highly trusted personnel only.
Additionally, web application firewalls can be configured to inspect control panel requests for known exploit patterns. Rules should block requests containing references to dynamic Yii behaviors or process execution paths. Specifically, payloads containing "class": "yii\\behaviors\\" or ConsoleProcessus should be flagged and rejected at the gateway level.
CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N| Product | Affected Versions | Fixed Version |
|---|---|---|
Craft CMS Craft CMS | >= 4.0.0-RC1, < 4.18.3 | 4.18.3 |
Craft CMS Craft CMS | >= 5.0.0-RC1, < 5.10.7 | 5.10.7 |
| Attribute | Detail |
|---|---|
| CWE ID | CWE-693 |
| Attack Vector | Network |
| CVSS v4.0 | 8.7 (High) |
| Privileges Required | Low |
| Exploit Status | Proof of Concept (PoC) |
| CISA KEV Listed | No |
The product does not use or incorrectly configures a protection mechanism, allowing attackers to bypass security controls.
Craft CMS contains an authenticated remote code execution vulnerability due to a sanitization bypass in its search condition configuration parser. An attacker with access to the control panel can inject unsafe Yii2 behavior configurations wrapped inside a JSON-encoded string. When decoded and merged by the application, these keys bypass the global config cleanse filter and are evaluated by the Yii2 component factory, leading to arbitrary code execution.
A high-severity authorization bypass vulnerability in Craft CMS allows authenticated users to reset arbitrary user passwords, including administrator accounts, by exploiting a mass assignment vulnerability in the User element model.
jsoup is a widely used Java library for working with real-world HTML. Versions 1.14.3 up to but excluding 1.23.1 contain a Cross-Site Scripting (XSS) vulnerability. When an application configures a custom Safelist that explicitly permits certain raw-text or RCDATA elements, such as style, title, or iframe, an attacker can exploit a parser-browser desynchronization flaw to bypass sanitization. This is achieved by utilizing trailing ASCII control characters that are handled differently by the HTML5 parsing specification and Java's string normalization methods, resulting in unescaped markup execution on the client side.
The ngx-extended-pdf-viewer library embeds a version of Mozilla's pdf.js that contains vulnerability CVE-2026-16633. This vulnerability allows arbitrary JavaScript execution (XSS) upon rendering a malicious PDF file.
A denial-of-service vulnerability in node-re2 prior to version 1.25.1 allows attackers to trigger uncatchable native assertion failures in the Google V8 engine. By supplying output-amplifying replacement templates, an attacker can exceed V8 string limits, resulting in an immediate process crash.
A medium-severity out-of-bounds (OOB) heap read vulnerability exists in node-re2 prior to version 1.26.1. When a raw binary Node.js Buffer with a truncated multi-byte UTF-8 character at its end is passed to the C++ native addon, the internal lookahead routine getUtf8CharSize() over-reads up to 3 bytes from the heap, leading to memory disclosure.