
Python proof-of-concept for CVE-2026-31857, an authenticated SSTI in Craft CMS control-panel condition rules that yields command execution via unsandboxed Twig object templates.
An authorized reproducer for an authenticated server-side template injection in Craft CMS. A user with control-panel access can reach a condition-builder sink that evaluates an attacker-controlled object template in an unsandboxed Twig context, enabling command execution as the web-service account.
The PoC defaults to the non-destructive id command. It verifies the authenticated
session after login and does not call an HTTP 200 proof of RCE unless expected command
output is also present.
>= 5.0.0-RC1, <= 5.9.8; fixed in 5.9.9.>= 4.0.0-beta.1, <= 4.17.3; fixed in 4.17.4.Check the official advisory and your vendor's backport information when assessing a packaged build.
The conditions system passes a controllable elementIds value to
renderObjectTemplate():
BaseElementSelectConditionRule::getElementIds()
-> Craft::$app->getView()->renderObjectTemplate($elementIds)
The PoC reaches that path through the control-panel element-search/search action using
an entry AuthorConditionRule. Object templates execute in a trusted Twig environment,
so the map("system") callback can invoke PHP's system() function:
{{ ["id"]|map("system")|join }}
The fix routes this value through the sandboxed object-template renderer. Settings such
as devMode=false do not repair a vulnerable release; upgrade to a fixed version.
The password is read from a hidden prompt, keeping it out of the process list and shell history:
python3 cve-2026-31857.py https://target.example editor
The default command is id, and the PoC requires uid= in the response before reporting
verified command execution. For automation, set CRAFT_PASSWORD in the environment.
For a custom, harmless marker:
python3 cve-2026-31857.py \
https://target.example editor \
'printf craft-31857-marker' \
--expect craft-31857-marker
Useful transport and evidence options:
python3 cve-2026-31857.py https://target.example editor id \
--proxy http://127.0.0.1:8080 \
--output conditions-response.html
Use --insecure only for an authorized lab with an intentionally untrusted TLS
certificate.
Use --site-id if the target's relevant Craft site is not ID 1. Some deployments may
buffer or suppress process output. In that case an HTTP 200 proves
only that the action accepted the request, not that the command ran. The script exits 3
and labels RCE unverified unless --expect (or the default id check) is found in the
response. Save the full response with --output, or use a separately authorized
out-of-band verification method.
Run the standard-library payload and workflow tests with python3 -m unittest -v.
For authorized security testing and research only. Use it only against systems you own or have explicit permission to test.