79% vs 51%: independent neobanks lag on app security. Read the report

Deep Dive

Deep Dive

Thymeleaf Restricted Expression Bypass RCE (CVE-2026-136410)

Thymeleaf 3.1.5 and earlier let input escape restricted expression mode, enabling template-injection RCE; fixed in 3.1.6.RELEASE.

TL;DR

  • Thymeleaf 3.1.5 and earlier let an expression escape the restricted mode that is meant to contain server-side template injection. The project published advisory GHSA-2wmw-5fmc-m25v on 2026-11-08.
  • An application is exposed when it builds a Thymeleaf expression from unvalidated user input and runs that expression in a restricted context such as th:utext, preprocessing, th:on* handlers, fragment names or TEXT templates.
  • The CVE record rates CVE-2026-136410 at CVSS v4.0 9.5 Critical and CVSS v3.1 9.0 Critical. No public proof of concept or in-the-wild exploitation is known, and the CVE is not in CISA KEV as of 2026-11-24.
  • Upgrade org.thymeleaf:thymeleaf, thymeleaf-spring5 and thymeleaf-spring6 to 3.1.6.RELEASE. See "How do I fix it?" for the Spring Boot property override.

Am I affected?

You are exposed when the application runs an affected Thymeleaf release and builds a template expression from input that an attacker can influence.

All of these conditions must hold:

  • The application depends on org.thymeleaf:thymeleaf, org.thymeleaf:thymeleaf-spring5 or org.thymeleaf:thymeleaf-spring6 at 3.1.5.RELEASE or earlier.
  • The application builds an expression from unvalidated input, for example by concatenating a request parameter into a template string before parsing it.
  • That expression executes in a restricted context: preprocessing (__${...}__), th:utext, a th:on* event handler, a fragment name, a TEXT template, or an unescaped inlined expression.
  • The attacker can reach that input over the network or through another untrusted channel.

Templates that only read context variables are not affected. A value passed as a context variable is data. The flaw appears when attacker input becomes part of the expression text that Thymeleaf parses.

Branch Affected versions Fixed version
Thymeleaf 3.1 3.1.0 through 3.1.5.RELEASE 3.1.6.RELEASE
thymeleaf-spring5 and thymeleaf-spring6 Same versions as the core artifact 3.1.6.RELEASE
Thymeleaf 3.0 and earlier All releases No fix; upgrade to 3.1.6.RELEASE

Thymeleaf is one of the template engines that Spring Boot auto-configures for server-side HTML, and the spring-boot-starter-thymeleaf starter pulls it into an application without an explicit version.

Check the resolved version with the build tool. For Maven:

mvn dependency:tree -Dincludes=org.thymeleaf

For Gradle:

./gradlew dependencyInsight --dependency org.thymeleaf:thymeleaf --configuration runtimeClasspath

For a packaged Spring Boot jar:

unzip -l target/application.jar | grep 'thymeleaf-.*\.jar'

Check whether the build pins the version through Spring Boot's dependency management:

grep -R "thymeleaf.version" pom.xml build.gradle build.gradle.kts

How do I fix it?

Upgrade the core artifact and the Spring integration artifact to 3.1.6.RELEASE, which the project released on 2026-11-08.

  1. Set the version in the dependency declaration. For Maven:
<dependency>
  <groupId>org.thymeleaf</groupId>
  <artifactId>thymeleaf</artifactId>
  <version>3.1.6.RELEASE</version>
</dependency>
  1. When Spring Boot's dependency management supplies Thymeleaf, override its version property instead of adding a second dependency. For Maven:
<properties>
  <thymeleaf.version>3.1.6.RELEASE</thymeleaf.version>
</properties>

For Gradle with the Spring Boot plugin and the Groovy DSL:

ext['thymeleaf.version'] = '3.1.6.RELEASE'

For Gradle with the Spring Boot plugin and the Kotlin DSL:

extra["thymeleaf.version"] = "3.1.6.RELEASE"
  1. Upgrade thymeleaf-spring6 or thymeleaf-spring5 in the same change. The Spring integration artifacts carry their own copy of the vulnerable evaluators.

  2. Rebuild the application, redeploy it, and confirm that the dependency tree now reports 3.1.6.RELEASE.

The advisory lists no workaround beyond the upgrade. The practical interim control is to stop passing unvalidated input into expressions. Validate the input against an allowlist and keep it in a context variable. That control is only as good as the code review behind it, because a single concatenation into parseExpression() or into a template string reopens the path.

What is the root cause?

Thymeleaf's restricted execution mode is a defence for expressions that run in contexts where output is not escaped. The mode is meant to stop an injected expression from instantiating classes, reading static fields or reaching parts of the context that ordinary template data does not need. In 3.1.5 the checks did not cover three paths, so an expression could run outside the mode's limits.

The OGNL evaluator checked only variable names. checkRestrictedVariables() walked the parsed tree and rejected restricted variable references such as request parameters. Member access itself allowed any public member of any target:

public boolean isAccessible(final Map context, final Object target, final Member member, final String propertyName) {
    int modifiers = member.getModifiers();
    if (!Modifier.isPublic(modifiers)) {
        return false;
    }
    if (member instanceof Method) {
        if (ExpressionUtils.isMemberForbidden(target, member.getName())) {
            throw new TemplateProcessingException(
                    String.format(
                            "Accessing member '%s' is forbidden for type '%s' in this expression context.",
                            member.getName(), target.getClass()));
        }
    }
    return true;
}

The evaluation root is the Thymeleaf context object. Because the member-access check did not treat an IContext target specially, a restricted expression could read the context object and call its public methods. The OGNL path also lacked the external-access check that the Spring evaluator applied to new and static references.

The Spring integration cached one expression object for both modes. obtainComputedSpelExpression() returned any cached ComputedSpelExpression without recording whether the expression had been parsed for a restricted execution:

Object cachedExpression = vexpression.getCachedExpression();
if (cachedExpression != null && cachedExpression instanceof ComputedSpelExpression) {
    return (ComputedSpelExpression) cachedExpression;
}
cachedExpression = getExpression(configuration, spelExpression);

Spring Expression Language nodes cache the property accessors and method executors that they resolve. A cached expression therefore kept the accessors from its first evaluation, and the restricted check in canRead() was skipped on later use. Compiled SpEL expressions also bypass the evaluation context for some operations, so the restricted flag could be ignored.

Inlined output applied the default execution context. AbstractStandardInliner.processExpression() parsed the inlined expression and executed it without the restricted mode:

final IStandardExpression expressionObj = expressionParser.parseExpression(context, unescapedExpression);
expressionResult = expressionObj.execute(context);

An unescaped inline expression therefore ran as a normal expression even when the surrounding template context expected restricted execution.

How is it exploited?

The flaw is a bypass of a containment control, so the attacker first needs an application that feeds input into an expression. Once that sink exists, the restricted mode fails to hold the expression to its intended limits.

  1. The application concatenates attacker input into a Thymeleaf expression, for example a template fragment, a fragment name or an inlined unescaped expression.
  2. Thymeleaf parses the resulting text as an expression and executes it in a restricted context. The application relies on restricted mode to limit what the expression can do.
  3. The expression reads the context object, or it matches a previously evaluated expression whose Spring accessors are already cached. The restricted checks do not run again on that path.
  4. The expression calls a method or a class that restricted mode is meant to deny. On the OGNL path, static access was not checked at all in this mode.
  5. The JVM executes the call with the application's permissions.

The advisory does not publish a proof-of-concept program, and no standalone exploit is known. The fix commit's regression tests show the expression shapes that the release now rejects in th:utext, including @java.lang.Math@max(1,2) and the same reference with lookalike characters around the @ signs.

How does the attack flow?

The attack is an expression injection that outlives the restricted mode: input reaches an expression, the restricted checks are skipped or incomplete, and a forbidden call runs in the application process.

flowchart LR A["User input becomes an expression"] --> B["Restricted context: th:utext or preprocessing"] B --> C["Restricted checks read the expression"] C --> D["Cached SpEL accessors or context object remain reachable"] D --> E["Forbidden method or class call is not blocked"] E --> F["Code runs in the application JVM"]

What can an attacker do?

An attacker who can inject into an expression can execute arbitrary code in the application's Java process. That process usually holds database credentials, signing keys, session stores and network access to internal services.

Every condition from "Am I affected?" still applies. The attacker needs the application to build an expression from untrusted input, the expression must run in a restricted context, and the input must reach that code. The CVE record marks confidentiality, integrity and availability as High with a changed scope, which reflects code execution outside the template's own sandbox.

The advisory describes the result as an escalation of an existing server-side template injection. It does not claim that every Thymeleaf application is remotely exploitable. An application that never builds expressions from input does not expose this path, even when it runs an affected version.

No in-the-wild exploitation and no public exploit code are known as of 2026-11-24.

Why does the fix work?

The release closes the three paths separately. OGNL now refuses any member access on the context object while restricted execution is active:

             if (!Modifier.isPublic(modifiers)) {
                 return false;
             }
+            if (target instanceof IContext
+                    && (!(context instanceof ThymeleafOGNLContext) || ((ThymeleafOGNLContext) context).restrictVariableAccess)) {
+                throw new TemplateProcessingException(
+                        String.format(
+                                "Accessing member '%s' of the context object is forbidden in this context.",
+                                member.getName()));
+            }

The Spring evaluator keeps restricted and unrestricted expressions in separate cache entries, disables SpEL compilation for restricted executions, and checks variable access again inside read() because an accessor can be cached on the syntax tree:

+        final boolean restricted = expContext.getRestrictVariableAccess();
...
-            cachedExpression = getExpression(configuration, spelExpression);
+            cachedExpression = getExpression(configuration, spelExpression, restricted);
...
-            exp = (ComputedSpelExpression) cache.get(new ExpressionCacheKey(EXPRESSION_CACHE_TYPE_SPEL,spelExpression));
+            exp = (ComputedSpelExpression) cache.get(new ExpressionCacheKey(cacheType, spelExpression));
...
-                    PARSER_WITH_COMPILED_SPEL != null && SpringStandardExpressions.isSpringELCompilerEnabled(configuration)?
+                    !restricted && PARSER_WITH_COMPILED_SPEL != null && SpringStandardExpressions.isSpringELCompilerEnabled(configuration)?

The same release adds an external-access check to the OGNL evaluator, applies the restricted execution context to inlined expressions, and applies it to link expression parameters. The advisory states that 3.1.6.RELEASE is the fix, and the commit series closes the three paths plus link-parameter hardening.

How do I check if I was compromised?

No indicators of compromise are published for this issue. A successful expression executes inside the application process and can leave no request-level trace beyond the input that carried it.

Review the code for expressions built from request data. Look for parseExpression() calls whose argument is concatenated, for template strings assembled from parameters, and for th:utext, th:on*, fragment names or preprocessing that include user-controlled values. This search narrows the review:

grep -REn '__\$\{|\bth:utext\b|\bth:on[a-z]+=' src/main/resources/templates

A hit is a lead, not proof. Static templates with no expression construction are normal and common.

Check web server and application logs for requests that contain expression syntax in parameters: ${, #{, @{, *{, @ followed by a class name, #ctx or T(. After the upgrade, Thymeleaf raises TemplateProcessingException with the message "forbidden in this context" when a restricted expression tries a blocked access. That message in the logs is a useful signal that an application is receiving injection attempts, though attempts that fail leave no other trace.

Timeline

  • 2026-11-08: GitHub advisory GHSA-2wmw-5fmc-m25v is published and Thymeleaf 3.1.6.RELEASE is released.
  • 2026-11-24: VulnCheck publishes CVE-2026-136410.

The fix shipped on the same day as the advisory, 16 days before the CVE record
Figure 1: Thymeleaf 3.1.6.RELEASE and the vendor advisory shipped on 2026-11-08; the CVE record followed on 2026-11-24. Source: GHSA-2wmw-5fmc-m25v, the 3.1.6.RELEASE release and CVE-2026-136410, checked November 24, 2026

FAQ

Does this affect Thymeleaf 3.0?

The advisory covers the 3.1 line through 3.1.5.RELEASE. Thymeleaf 3.0 is an older, unsupported line, so treat it as affected and move to 3.1.6.RELEASE.

Does this affect Spring Boot applications?

Yes, when the application resolves an affected Thymeleaf version. Spring Boot auto-configures Thymeleaf and its starter brings the library transitively, so check the resolved version with mvn dependency:tree -Dincludes=org.thymeleaf before assuming the Boot upgrade changed it.

Is there a public exploit or in-the-wild exploitation?

No public proof of concept and no in-the-wild exploitation are known, and the CVE is not in CISA KEV as of 2026-11-24. The advisory and the fix tests document the expression shapes that the release now blocks.

Is th:text safe?

th:text escapes output and is not one of the restricted contexts named in the advisory. The vulnerability is about expressions that an application builds from input, not about the escaping of ordinary context variables.

Which artifacts do I upgrade?

Upgrade org.thymeleaf:thymeleaf and the Spring integration artifact the application uses, thymeleaf-spring5 or thymeleaf-spring6, to 3.1.6.RELEASE. A version override for the core artifact alone can leave the integration artifact at an affected version.

Can I keep the current version if I validate input?

No validated control is published, and the advisory recommends the upgrade. Input validation reduces the chance that an attacker reaches an expression, but it does not repair the restricted mode and it depends on every code path being reviewed.

Find template-injection sinks in your Spring applications with Ostorlab

Ostorlab's web agentic deep scan tests web applications and APIs for injection classes, including template and expression injection, so a team can locate the code paths that build expressions from request data. Detection of CVE-2026-136410 itself is not confirmed.

References

Free scan

Scan your own app for free

or book a demo

Keep reading

Related articles

Browse the blog