Skip to main content
Press slash or control plus K to focus the search. Use the arrow keys to navigate results and press enter to open a threat.
Reconnecting to live updates…

CVE-2026-31857: CWE-94: Improper Control of Generation of Code ('Code Injection') in craftcms cms

0
High
VulnerabilityCVE-2026-31857cvecve-2026-31857cwe-94
Published: Wed Mar 11 2026 (03/11/2026, 17:30:29 UTC)
Source: CVE Database V5
Vendor/Project: craftcms
Product: cms

Description

CVE-2026-31857 is a high-severity remote code execution vulnerability in Craft CMS versions prior to 5. 9. 9 and 4. 17. 4. It arises from improper control of code generation (CWE-94) in the BaseElementSelectConditionRule::getElementIds() method, which unsafely renders user-controlled input through an unsandboxed Twig template with escaping disabled. Any authenticated Control Panel user, including those with minimal roles like Author or Editor, can exploit this vulnerability without admin privileges or special permissions. The exploit bypasses common production hardening settings such as disabling admin changes, dev mode, and enabling Twig sandboxing. Successful exploitation allows full remote code execution on the server hosting the CMS. Organizations should urgently update to the patched versions 5.

AI-Powered Analysis

AILast updated: 03/11/2026, 18:00:20 UTC

Technical Analysis

CVE-2026-31857 is a critical remote code execution (RCE) vulnerability affecting Craft CMS, a popular content management system. The flaw exists in the BaseElementSelectConditionRule::getElementIds() method, which processes user input through the renderObjectTemplate() function. This function uses Twig templates but does so without sandboxing and with escaping disabled, allowing user-controlled strings to be interpreted as executable code. The vulnerability is particularly dangerous because it can be exploited by any authenticated user with access to the Control Panel, including low-privilege roles such as Authors or Editors. No administrative privileges or special permissions are required, and the exploit bypasses typical production hardening configurations like allowAdminChanges set to false, devMode disabled, and enableTwigSandbox enabled. The vulnerability affects Craft CMS versions from 4.0.0-beta.1 up to but not including 4.17.4, and from 5.0.0-RC1 up to but not including 5.9.9. The CVSS 4.0 base score is 8.1, reflecting high severity due to network attack vector, no required privileges or user interaction, and high impact on confidentiality, integrity, and availability. Although no active exploits have been reported, the vulnerability's characteristics make it a prime target for attackers seeking to gain full control over vulnerable CMS installations. The recommended mitigation is immediate upgrade to patched versions 5.9.9 or 4.17.4. Additional mitigations include restricting Control Panel access to trusted users, monitoring for unusual activity, and applying web application firewall (WAF) rules to detect exploitation attempts.

Potential Impact

The impact of CVE-2026-31857 is severe for organizations using affected versions of Craft CMS. Successful exploitation results in full remote code execution on the web server, allowing attackers to execute arbitrary commands, deploy malware, steal sensitive data, or pivot to internal networks. Because the vulnerability can be exploited by low-privilege authenticated users, insider threats or compromised accounts can lead to complete system compromise. The bypass of common hardening settings increases the risk in production environments that rely on these mitigations. Organizations running Craft CMS in sectors such as media, e-commerce, education, and government may face data breaches, service disruptions, reputational damage, and regulatory penalties. The ease of exploitation and high impact on confidentiality, integrity, and availability make this a critical risk that demands immediate attention.

Mitigation Recommendations

1. Immediately upgrade Craft CMS to version 5.9.9 or 4.17.4 or later, as these versions contain the patch for this vulnerability. 2. Restrict Control Panel access strictly to trusted users and minimize the number of users with any Control Panel permissions, especially those with roles such as Author or Editor. 3. Implement strong authentication mechanisms, including multi-factor authentication (MFA), to reduce the risk of compromised credentials. 4. Monitor Control Panel access logs and server logs for unusual or suspicious activity indicative of exploitation attempts. 5. Deploy web application firewalls (WAFs) with custom rules to detect and block malicious payloads targeting Twig template rendering or unusual requests to element listing endpoints. 6. Regularly audit user roles and permissions to ensure least privilege principles are enforced. 7. Consider network segmentation and isolation of CMS servers to limit lateral movement in case of compromise. 8. Keep all CMS plugins and dependencies up to date to reduce the attack surface. 9. Educate users with Control Panel access about phishing and credential security to prevent account takeover.

Pro Console: star threats, build custom feeds, automate alerts via Slack, email & webhooks.Upgrade to Pro

Technical Details

Data Version
5.2
Assigner Short Name
GitHub_M
Date Reserved
2026-03-09T19:02:25.011Z
Cvss Version
4.0
State
PUBLISHED

Threat ID: 69b1aa112f860ef943525d7e

Added to database: 3/11/2026, 5:44:49 PM

Last enriched: 3/11/2026, 6:00:20 PM

Last updated: 3/11/2026, 6:46:14 PM

Views: 4

Community Reviews

0 reviews

Crowdsource mitigation strategies, share intel context, and vote on the most helpful responses. Sign in to add your voice and help keep defenders ahead.

Sort by
Loading community insights…

Want to contribute mitigation steps or threat intel context? Sign in or create an account to join the community discussion.

Actions

PRO

Updates to AI analysis require Pro Console access. Upgrade inside Console → Billing.

Please log in to the Console to use AI analysis features.

Need more coverage?

Upgrade to Pro Console in Console -> Billing for AI refresh and higher limits.

For incident response and remediation, OffSeq services can help resolve threats faster.

Latest Threats

Breach by OffSeqOFFSEQFRIENDS — 25% OFF

Check if your credentials are on the dark web

Instant breach scanning across billions of leaked records. Free tier available.

Scan now
OffSeq TrainingCredly Certified

Lead Pen Test Professional

Technical5-day eLearningPECB Accredited
View courses