CVEReports
CVEReports

Automated vulnerability intelligence platform. Comprehensive reports for high-severity CVEs generated by AI.

Product

  • Home
  • Sitemap
  • RSS Feed

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 CVEReports. All rights reserved.

Made with love by Amit Schendel & Alon Barad



CVE-2026-31857

CVE-2026-31857: Authenticated Remote Code Execution in Craft CMS via Server-Side Template Injection

Alon Barad
Alon Barad
Software Engineer

Mar 12, 2026·4 min read·38 visits

Executive Summary (TL;DR)

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.

Vulnerability Overview

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.

Root Cause Analysis

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.

Code Analysis

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 Methodology

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.

Impact Assessment

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.

Remediation and Mitigation

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.

Fix Analysis (2)

Technical Appendix

CVSS Score
8.1/ 10
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

Affected Systems

Craft CMS 4Craft CMS 5

Affected Versions Detail

Product
Affected Versions
Fixed Version
Craft CMS 5
craftcms
>= 5.0.0-RC1, < 5.9.95.9.9
Craft CMS 4
craftcms
>= 4.0.0-beta.1, < 4.17.44.17.4
AttributeDetail
CWE IDCWE-94
CVSS 4.0 Score8.1
Attack VectorNetwork
Authentication RequiredYes
Exploit StatusProof of Concept
KEV ListedNo

MITRE ATT&CK Mapping

T1059Command and Scripting Interpreter
Execution
T1203Exploitation for Client Execution
Execution
CWE-94
Improper Control of Generation of Code ('Code Injection')

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.

Vulnerability Timeline

Initial commits addressing create() Twig function restrictions
2026-02-05
Release of Craft CMS 5.9.9 and 4.17.4 with the vulnerability fix
2026-02-11
Official publication of CVE-2026-31857
2026-03-11

References & Sources

  • [1]NVD Record: CVE-2026-31857
  • [2]GitHub Advisory: GHSA-fp5j-j7j4-mcxc
  • [3]Fix Commit (5.x)
  • [4]Fix Commit (4.x)
  • [5]Craft CMS Changelog

Attack Flow Diagram

Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.

More Reports

•about 3 hours ago•CVE-2024-29203
4.3

CVE-2024-29203: Client-Side Cross-Site Scripting via Unsandboxed Iframes and Legacy Embed Elements in TinyMCE

CVE-2024-29203 identifies a cross-site scripting (XSS) vulnerability in the content ingestion and parsing mechanics of TinyMCE rich text editor. Due to a failure to enforce sandbox attributes on dynamic iframe elements and safely handle legacy embed objects, unauthenticated attackers can inject malicious elements that execute scripts within the context of the parent application session.

Amit Schendel
Amit Schendel
5 views•5 min read
•about 5 hours ago•CVE-2026-9277
8.1

CVE-2026-9277: OS Command Injection in shell-quote via Object-Token Line Terminator Parsing Defect

A technical breakdown of the OS command injection vulnerability in the shell-quote NPM package (CVE-2026-9277 / GHSA-w7jw-789q-3m8p). The bug resides in the character-by-character backslash-escaping logic applied to the .op field of object-tokens within the quote() function, which fails to match and escape line terminators due to a regex matching oversight in JavaScript. This allows unauthenticated remote attackers to execute arbitrary shell commands if they can control inputs processed by this library.

Alon Barad
Alon Barad
7 views•6 min read
•about 6 hours ago•CVE-2026-11645
8.8

CVE-2026-11645: Out-of-Bounds Memory Access in Google Chrome V8 Engine

A high-severity memory corruption vulnerability exists in the V8 JavaScript engine of Google Chrome before versions 149.0.7827.102/103. The flaw arises from an incorrect bounds-check elimination during JIT compilation by the TurboFan optimizer, allowing remote attackers to achieve out-of-bounds read and write access inside the sandboxed renderer process.

Amit Schendel
Amit Schendel
22 views•6 min read
•about 15 hours ago•CVE-2026-50751
9.3

CVE-2026-50751: Authentication Bypass in Check Point Security Gateway IKEv1 Legacy Validation

An improper authentication vulnerability (CWE-287) exists in the legacy, deprecated Internet Key Exchange version 1 (IKEv1) key exchange protocol implementation in Check Point Security Gateways. The vulnerability is caused by a logic flow weakness during the certificate validation process for Remote Access VPN and Mobile Access (SSL VPN) connections. An unauthenticated remote attacker can exploit this weakness to bypass user authentication entirely, establishing a fully functional Remote Access VPN connection without a valid password.

Alon Barad
Alon Barad
68 views•6 min read
•1 day ago•CVE-2026-39922
6.3

CVE-2026-39922: Server-Side Request Forgery in GeoNode Service Registration Endpoint

GeoNode versions prior to 4.4.5 and 5.0.2 are vulnerable to Server-Side Request Forgery (SSRF) in the service registration endpoint. Authenticated attackers with low privileges can exploit insufficient input validation in the Web Map Service (WMS) registration module to force the application server to make outbound network queries to loopback addresses, private RFC1918 subnets, link-local scopes, and cloud metadata endpoints. This technical report details the mechanics of the vulnerability, the underlying architectural flaw, and how to effectively remediate and mitigate the associated security risks.

Alon Barad
Alon Barad
4 views•7 min read
•1 day ago•CVE-2022-0492
7.8

CVE-2022-0492: Privilege Escalation and Container Escape via cgroups v1 release_agent

CVE-2022-0492 is a high-severity missing authorization vulnerability in the Linux kernel's Control Groups (cgroups) v1 implementation. The flaw resides within the cgroup_release_agent_write function in kernel/cgroup/cgroup-v1.c, where the kernel fails to validate if the process writing to the release_agent file possesses administrative capabilities in the initial user namespace. This allows a local attacker inside a container with root privileges (UID 0) to abuse user namespaces, mount a cgroups v1 directory, modify the release_agent parameter, and execute arbitrary commands on the host system as host root, effectively achieving a complete container escape.

Amit Schendel
Amit Schendel
12 views•7 min read