Mar 12, 2026·4 min read·51 visits
Authenticated users can achieve Remote Code Execution in Craft CMS by injecting malicious Twig payloads into relational condition rules, bypassing production security restrictions.
Craft CMS versions 4.x and 5.x are vulnerable to a high-severity Server-Side Template Injection (SSTI) flaw. Authenticated attackers with minimal Control Panel permissions can execute arbitrary PHP code. The vulnerability exists in the processing of relational condition rules within the element index and search functionalities.
Craft CMS utilizes a conditions system to manage relational condition rules for element filtering and searching within the Control Panel. This system processes dynamic strings through the Twig templating engine to resolve element IDs. A Server-Side Template Injection (SSTI) vulnerability occurs when user-supplied input is processed by this system without adequate sanitization or sandboxing.
The flaw allows authenticated users, including those with restricted roles such as Authors or Editors, to supply arbitrary Twig templates. These templates are evaluated by the backend server. Because the templates are processed in an unsandboxed environment, an attacker can invoke native PHP functions.
The vulnerability is tracked as CVE-2026-31857 and carries a CVSS 4.0 score of 8.1. It represents a significant privilege escalation vector, allowing low-privileged users to achieve full Remote Code Execution (RCE) on the underlying host infrastructure.
The vulnerability originates in the BaseElementSelectConditionRule class. This class handles relational filters, such as filtering entries that are related to specific IDs. The methods getElementId() and getElementIds() process user-supplied element ID strings to resolve relational queries.
These methods pass the element ID strings directly to Craft::$app->getView()->renderObjectTemplate(). This utility function evaluates dynamic strings containing Twig syntax. Prior to the patch, this function operated without a Twig sandbox and with auto-escaping disabled.
The absence of a sandbox grants the template full access to the Twig environment. This includes access to the global craft object and powerful template filters. Consequently, any executable code embedded within the Twig syntax is processed and executed by the PHP interpreter.
The patch remediates the vulnerability by enforcing sandboxed execution for object templates. The insecure renderObjectTemplate method call was replaced with renderSandboxedObjectTemplate.
// Vulnerable Code (src/base/conditions/BaseElementSelectConditionRule.php)
- return Craft::$app->getView()->renderObjectTemplate($elementId, $referenceElement);
// Patched Code
+ return Craft::$app->getView()->renderSandboxedObjectTemplate($elementId, $referenceElement);The vendor also implemented supplementary defense-in-depth measures to prevent secondary injection vectors. A new helper method, ElementHelper::cleanseQueryCriteria(), was introduced to sanitize user-submitted criteria arrays.
// src/helpers/ElementHelper.php
public static function cleanseQueryCriteria(array $criteria): array {
unset(
$criteria['where'], $criteria['orderBy'], $criteria['indexBy'],
$criteria['select'], $criteria['selectOption'], $criteria['from'],
$criteria['groupBy'], $criteria['join'], $criteria['having'],
$criteria['union'], $criteria['withQueries'], $criteria['params']
);
return $criteria;
}This helper strips dangerous SQL-related keys before the criteria array is passed to the ElementQuery builder. This mitigates related SQL injection vulnerabilities tracked under GHSA-g7j6-fmwx-7vp8.
Exploitation requires the attacker to hold an authenticated session with access to the Control Panel. The attacker targets endpoints responsible for element indexes or saved searches, such as /index.php?p=admin/actions/element-indexes/save-index.
The attacker submits an HTTP POST request containing a maliciously crafted $criteria array. This array defines a relational condition rule where the "Element ID" template contains the Twig payload. When the backend processes this rule, the payload is executed.
Valid payloads leverage Twig filters or global objects to invoke PHP functions. For example, the payload {{ ["id"]|map("phpinfo") }} utilizes the map filter to execute the phpinfo function. Alternatively, {{craft.app.view.evaluateDynamicContent('system("whoami")')}} accesses the App instance directly to execute system commands.
Successful exploitation results in arbitrary PHP code execution within the context of the web server process. The attacker gains the ability to read sensitive files, modify the database, or establish persistent access to the host operating system.
The vulnerability circumvents standard Craft CMS production hardening configurations. Specifically, the exploit functions even when allowAdminChanges and devMode are disabled. The global enableTwigSandbox configuration does not prevent this attack because the vulnerable rendering function explicitly bypassed the sandbox.
This significantly elevates the risk profile for environments that grant Author or Editor permissions to untrusted or external users. A compromised low-privileged account can be immediately leveraged to completely compromise the application and the underlying infrastructure.
Administrators must upgrade Craft CMS deployments to version 5.9.9 or 4.17.4 to address this vulnerability. These versions enforce sandboxing within the relational condition rule processing and introduce necessary query cleansing.
If immediate patching is not feasible, organizations should restrict Control Panel access to highly trusted administrators. Auditing existing user permissions is recommended to minimize the attack surface.
Security teams can deploy Web Application Firewall (WAF) rules to detect and block common Twig SSTI patterns. Rules should inspect POST requests directed at /index.php?p=admin/actions/element-indexes/* for strings such as {{, |map, |filter, and evaluateDynamicContent.
CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N/E:U| Product | Affected Versions | Fixed Version |
|---|---|---|
Craft CMS 5 craftcms | >= 5.0.0-RC1, < 5.9.9 | 5.9.9 |
Craft CMS 4 craftcms | >= 4.0.0-beta.1, < 4.17.4 | 4.17.4 |
| Attribute | Detail |
|---|---|
| CWE ID | CWE-94 |
| CVSS 4.0 Score | 8.1 |
| Attack Vector | Network |
| Authentication Required | Yes |
| Exploit Status | Proof of Concept |
| KEV Listed | No |
The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended syntax or behavior of the generated code.
An uncontrolled resource consumption vulnerability exists in the Scala-based http4s-blaze-server package of the http4s/blaze library. The vulnerability allows remote, unauthenticated attackers to cause an Out of Memory Error (OOM) and JVM crash by streaming a continuous sequence of small or empty WebSocket continuation frames with the FIN bit set to 0. This bypasses typical payload size checks because of the JVM's per-object allocation overhead, leading to rapid heap exhaustion with minimal network bandwidth.
A critical path traversal vulnerability has been identified in the OpenList Go-based backend package. The vulnerability exists within the batch rename handler because the application does not validate the source filename parameter before constructing filesystems paths. This omission allows authenticated users to escape their designated directory and rename files in sibling paths.
OpenList version 4.2.3 and prior is vulnerable to an authorization bypass and metadata leakage. When configured with the Bleve search engine backend, OpenList fails to perform separator-aware path matching when validating tenant containment. This allows authenticated users to access sibling directories sharing similar name prefixes. Furthermore, the search backend returns unfiltered global result counts, leaking existence verification data of unauthorized files via side-channel analysis.
An authorization bypass vulnerability in OpenList version 4.2.3 and below allows authenticated users to read arbitrary files outside of their designated base directories due to an insecure path prefix check using Go's standard strings.HasPrefix function.
A security policy bypass vulnerability exists in the AWS API MCP Server (awslabs-aws-api-mcp-server) from version 0.2.13 through 1.3.46. When the server fails to load the read-only operations index during startup (due to transient network failures, file permission issues, or other exceptions), it logs a warning but continues running in an insecure, degraded state. Under this condition, the security policy engine fails open, silently skipping all subsequent security checks and consent prompts for the lifetime of the process. This permits unauthorized mutating AWS CLI commands to execute via indirect prompt injection attacks.
An incomplete escaping vulnerability in the npm package 'shescape' allows unauthenticated users to trigger dynamic shell expansions, absolute path disclosure, and command block break-outs on Unix and Windows systems.