Aug 7, 2026·6 min read·13 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.
Docling prior to version 2.131.0 is vulnerable to arbitrary local code execution during module initialization due to incorrect order of operations in its plugin discovery system. Even when the default option to reject external plugins is active, Docling utilizes Pluggy to scan and import entrypoints before performing namespace validation.
An uncontrolled resource consumption vulnerability exists in the Docling document conversion library. Maliciously structured HTML, JATS, ODS, or BoxNote inputs containing table cells with excessively large 'rowspan' or 'colspan' attribute values trigger algorithmic complexity conditions. This allows unauthenticated remote attackers to initiate resource exhaustion states, crashing or hanging the target document processing pipeline while bypassing configured timeouts.
A Local File Inclusion (LFI) and Arbitrary File Disclosure vulnerability exists in Docling and Docling Slim versions >= 2.16.0 up to 2.131.0. When parsing serialized DoclingDocument structures using the JSON input format, the backend fails to restrict image URI schemes, allowing remote attackers to retrieve local files and verify path existence on the host system during embedded document export.
Docling, a tool for parsing and processing diverse document formats, is vulnerable to arbitrary file read, arbitrary file write, and potential remote code execution (RCE) in versions 2.94.0 through 2.131.0. The vulnerability occurs when applications configure Docling to use the Tectonic engine for rendering TikZ diagrams into images. Because the compilation did not restrict hazardous TeX primitives or sandbox the environment, an attacker can supply crafted documents containing malicious TikZ definitions to access or modify local files and execute arbitrary commands under the privileges of the processing application.
An SSRF guard bypass vulnerability in the Docling document conversion engine allows unauthenticated attackers to bypass internal IP access controls. The vulnerability exists due to a DNS rebinding Time-of-Check Time-of-Use (TOCTOU) condition, URL authority parsing inconsistencies, and unvalidated network requests triggered during headless browser page rendering.
A technical analysis of CVE-2026-105742 (GHSA-p3fw-7699-7926), a sensitive information disclosure vulnerability in the Docling document processing library. Vulnerable versions of Docling indiscriminately forward custom HTTP headers, such as authentication tokens, to arbitrary third-party origins and during cross-origin redirects while fetching remote image assets from untrusted HTML and EPUB documents.