CVE-2026-40477

Remote Code Execution
Affects
Thymeleaf
in
Thymeleaf
No items found.
Versions
<=3.1.3.RELEASE

Patch Available.

Exclamation circle icon
Patch Available

This Vulnerability has been fixed in the Never-Ending Support (NES) version offered by HeroDevs.

Overview

Thymeleaf is a modern server-side Java template engine for both web and standalone environments. It processes HTML, XML, text, JavaScript and CSS templates and is widely used as the view layer of Spring MVC and Spring Boot applications. Thymeleaf 3.0.x is the legacy line; Thymeleaf 3.1.x is the current upstream line.

A remote code execution vulnerability (CVE-2026-40477) has been identified in Thymeleaf's restricted expression mode, which allows attackers who can get unvalidated input into a template expression to reach sensitive expression objects and bypass the engine's expression-injection protections, leading to Server-Side Template Injection (SSTI).

Per OWASP: Code Injection is the general term for attack types which consist of injecting code that is then interpreted/executed by the application. This type of attack exploits poor handling of untrusted data.

This issue affects all versions of Thymeleaf up to and including 3.1.3.RELEASE.

Details

Module Info

Vulnerability Info

This Critical-severity vulnerability is found in the org.thymeleaf:thymeleaf package in all versions of Thymeleaf up to and including 3.1.3.RELEASE.

Thymeleaf evaluates expressions that may carry untrusted input, such as unescaped text (th:utext), text-mode output and inlining, expression preprocessing (__${...}__), and fragment and link expressions, in a restricted execution mode. Restricted mode is the engine's expression-injection protection: it forbids object instantiation and static access, and it wraps the request object so that request parameters cannot be read.

The restriction only covers the request objects. OGNLExpressionObjectsWrapper.get() hands every other expression object to a restricted expression unchanged, including the ones that expose the live evaluation context: #ctx, #vars, #root, #this and #execInfo.

@Override
public Object get(final Object key) {

    if (this.expressionObjects.containsObject(key.toString())) {

        final Object expressionObject = this.expressionObjects.getObject(key.toString());

        // We need to first check if we are in a restricted environment. If so, restrict access to the request.
        if (this.restrictedExpressionExecution &&
                (StandardExpressionObjectFactory.REQUEST_EXPRESSION_OBJECT_NAME.equals(key) ||
                 StandardExpressionObjectFactory.HTTP_SERVLET_REQUEST_EXPRESSION_OBJECT_NAME.equals(key))) {
            return RestrictedRequestAccessUtils.wrapRequestObject(expressionObject);
        }

        return expressionObject;
    }

    return super.get(key);

}

Method calls on reachable objects are not restricted, so an injected expression can start from one of these objects and walk to whatever it exposes. From #ctx, that includes the unwrapped request, the response and the servlet context. The request-parameter restriction is bypassed with an expression as short as ${#ctx.getRequest().getParameter('name')}, and the same reach is the starting point for full template injection.

Steps to Reproduce

  1. Process a template whose th:utext attribute, a restricted context, evaluates an expression that references #ctx, as an injected expression would:
    <div th:utext="${#ctx.getVariable('somevar')}">...</div>
  2. On an affected version, the template renders the variable's value. A version with the fix rejects the expression with "Access to variable '#ctx' is forbidden in this context."

Mitigation

Older versions of Thymeleaf are End-of-Life and will not receive any updates to address this issue.

Users of the affected components should apply one of the following mitigations:

  • Upgrade applications to a supported version of Thymeleaf.
  • Leverage a commercial support partner like HeroDevs for post-EOL security support.

Credits

  • Thomas Reburn from Praetorian (finder)
Vulnerability Details
Severity
Level
CVSS Assessment
Low
>=0 <4
Medium
>=4 <6
High
>=6 <8
Critical
>=8 <10
Critical
ID
CVE-2026-40477
PROJECT Affected
Thymeleaf
Versions Affected
<=3.1.3.RELEASE
NES Versions Affected
Published date
October 21, 2026
≈ Fix date
October 16, 2026
Category
Remote Code Execution
Vex Document
Download VEXHow do I use it?
Sign up for the latest vulnerability alerts fixed in
NES for Thymeleaf
Rss feed icon
Subscribe via RSS
or

By submitting the form I acknowledge receipt of our Privacy Policy.

Thanks for signing up for our Newsletter! We look forward to connecting with you.
Oops! Something went wrong while submitting the form.