Thymeleaf SpEL Injection Remote Code Execution (CVE-2026-41901)
by HORKimhab · 2026-07-05
- Severity
- Critical
- CVE
- CVE-2026-41901
- Category
- web
- Affected product
- Spring Boot application using Thymeleaf template engine
- Affected versions
- Thymeleaf 3.1.4.RELEASE (as configured in the reproduction lab)
- Disclosed
- 2026-07-05
- Patch status
- unpatched
References
Archive entry
intelseclab/poc-archiveMetadata
| Field | Value |
|---|---|
| Date Added | 2026-07-05 |
| Last Updated | 2026-05 |
| Author / Researcher | HORKimhab |
| CVE / Advisory | CVE-2026-41901 |
| Category | web |
| Severity | Critical |
| CVSS Score | Not specified in source |
| Status | PoC |
| Tags | thymeleaf, spel-injection, ssti, spring-boot, rce, java, template-injection |
| Related | N/A |
Affected Target
| Field | Value |
|---|---|
| Software / System | Spring Boot application using Thymeleaf template engine |
| Versions Affected | Thymeleaf 3.1.4.RELEASE (as configured in the reproduction lab) |
| Language / Platform | Java/Spring Boot target, bash/curl PoC |
| Authentication Required | No |
| Network Access Required | Yes |
Summary
The PoC reproduces a Spring Expression Language (SpEL) injection in a Thymeleaf-rendered template where user-controlled input is reflected into a template expression context without sanitization. By submitting a crafted SpEL payload such as [[${T(java.lang.Runtime).getRuntime().exec("id")}]] as the input query parameter, an attacker can get the Thymeleaf engine to evaluate the expression and invoke arbitrary Java classes, including java.lang.Runtime, achieving remote command execution on the server. The included lab setup script builds a minimal vulnerable Spring Boot/Thymeleaf application in Docker, and the exploit script sends a battery of SpEL payloads to demonstrate command execution and output capture via java.util.Scanner.
Vulnerability Details
Root Cause
The vulnerable controller passes attacker-controlled input directly into a Thymeleaf template attribute (th:text="${userInput}" and inline expressions), and the template additionally contains a SpEL expression that invokes T(java.lang.Runtime).getRuntime().exec(...), allowing arbitrary command execution when the expression is evaluated with attacker input.
Attack Vector
- Attacker identifies a Thymeleaf-rendered endpoint (e.g.
/poc?input=...) that reflects user input into the template context. - Attacker submits a SpEL payload such as
[[${T(java.util.Scanner).new(T(java.lang.Runtime).getRuntime().exec("id").getInputStream()).useDelimiter("\A").next()}]]via theinputparameter. - Thymeleaf evaluates the SpEL expression server-side, invoking
Runtime.exec()with the attacker-supplied command. - The command’s output is captured via
java.util.Scannerand reflected back in the HTTP response, giving the attacker semi-interactive command execution and output retrieval.
Impact
Full remote code execution on the Spring Boot server as the application’s runtime user, with the ability to read arbitrary files and execute arbitrary OS commands.
Environment / Lab Setup
Target: Spring Boot 3.2.0 app with Thymeleaf 3.1.4.RELEASE, packaged in Docker (thymeleaf-rce container, port 8080)
Attacker: bash, curl, Docker (to build/run the vulnerable lab)
Proof of Concept
PoC Script
See
setup-lab.shandexploit-cve-2026-41901.shin this folder.
| |
setup-lab.sh scaffolds and builds a minimal vulnerable Spring Boot/Thymeleaf application in Docker and exposes it on port 8080. exploit-cve-2026-41901.sh then sends a series of SpEL injection payloads (id, whoami, hostname, ls /tmp, cat /etc/passwd) to the /poc endpoint and prints any command output reflected in the response.
Detection & Indicators of Compromise
Signs of compromise:
- Web server or WAF logs showing
T(java.lang.Runtime),ProcessBuilder, or[[${...}]]sequences in request parameters - Unexpected child processes spawned by the Java/Spring Boot process
- Command output (e.g.
/etc/passwdcontents,id/whoamioutput) appearing in HTTP responses
Remediation
| Action | Detail |
|---|---|
| Primary fix | No vendor patch confirmed as of 2026-07-05 — do not reflect unsanitized user input into Thymeleaf expression contexts; avoid th:text/inline expressions over raw user input |
| Interim mitigation | Disable SpEL expression evaluation on untrusted input paths, apply strict input validation/allow-listing, and run the application with a restricted user and no shell/process-execution capability |
References
Notes
Mirrored from https://github.com/HORKimhab/CVE-2026-41901 on 2026-07-05.
| |