Java Template Engine SSTI
Template injection in FreeMarker, Thymeleaf, Velocity, Pebble, Jinjava and Jelly. RCE comes from the JVM’s reflective reach and permissive engine defaults.
How it works
Java engines give templates access to Java objects. Unless the configuration restricts it, that reach extends to class instantiation and reflection. Engine-specific surfaces:
| Engine | RCE-relevant surface | Hardening knob |
|---|---|---|
| FreeMarker | ?new() built-in instantiating TemplateModel classes; ?api exposing the underlying Java API; object wrapper internals (DEFAULT_WRAPPER) | TemplateClassResolver.ALLOWS_NOTHING_RESOLVER, api_builtin_enabled=false |
| Thymeleaf | Variable expressions evaluated as SpEL/OGNL; expression preprocessing __${...}__; user-controlled view names / fragment paths in Spring MVC | Thymeleaf 3.1 restricted-expression denylist (bypassed repeatedly) |
| Velocity | Reflection via exposed objects ($class-style access) | SecureUberspector |
| Pebble / Jinjava | Method calls on context objects, dynamic class loading | method access policies |
| Jelly (ServiceNow) | XML template tags evaluated server-side | — |
- Spring view-name injection. In Thymeleaf + Spring, a controller that returns a user-influenced view name or fragment selector is evaluated through preprocessing. The Acunetix PetClinic
pathexample and Snyk’s CVE-2026-40478 analysis both depend on this misuse pattern. - Overlap with EL/OGNL. Thymeleaf’s expression layer is SpEL/OGNL, so the line between template injection and Expression Language Injection blurs. Confluence CVE-2022-26134 is OGNL injection, often filed next to SSTI.
Sandbox and denylist bypass themes
- FreeMarker: a YouTrack (CVE-2021-25770) sandbox bypass went through the object wrapper despite
ALLOWS_NOTHING_RESOLVER, based on Black Hat USA 2020 research. Synack used?lower_abc/?upper_abcto rebuild filtered strings. - Thymeleaf: the 3.1 denylist was bypassed via third-party reflection helpers on the classpath, e.g. commons-lang3
MethodUtils(modzero). Other bypasses: a tab character inside sandboxed expressions (CVE-2026-40478, fixed in 3.1.4) and a further unrecognized-syntax bypass fixed in 3.1.5. Spring Boot Admin CVE-2022-46166 abused a remote MailNotifier template (Thymeleaf ≤3.1.1). - Lesson: denylists of classes and methods lose to whatever reflective utilities sit on the classpath.
Notable cases
| Product | ID | Notes |
|---|---|---|
| ServiceNow | CVE-2024-4879, -5178, -5217 | Jelly template injection, unauth RCE chain; CISA KEV; mass recon campaign |
| Atlassian Confluence | CVE-2019-3396 | Widget Connector: uploaded Velocity template |
| Atlassian Bamboo DC | CVE-2026-21596 | authenticated SSTI → command exec (12.0.0–12.1.x) |
| Apache OFBiz | CVE-2026-82910 | MacroScreenRenderer link params concatenated into FreeMarker |
| JetBrains TeamCity | <2026.2.2 / <2026.1.6 | FreeMarker injection RCE |
| JetBrains YouTrack | CVE-2021-25770 | FreeMarker sandbox bypass |
| Alfresco | CVE-2023-49964 | FreeMarker in folder.get.html.ftl; builds on CVE-2020-12873 |
| Apache StreamPark | CVE-2024-29178 | FreeMarker, authenticated |
| Apache Camel | CVE-2020-11994 | template header / resource URI control (FreeMarker, Velocity, MVEL, Mustache) |
| openEQUELLA | <2026.1.0 | permissive FreeMarker defaults (?new(), ?api) |
| OpenMetadata | GHSA-5f29-2333-h9c7 | admin-editable FreeMarker email templates |
| Spring Boot Admin | CVE-2022-46166 | Thymeleaf sandbox bypass via notifier template |
| Thymeleaf Spring5 | CVE-2021-43466 | AjaxThymeleafView render |
Defenses
- Never build view names, fragment selectors or template strings from request data. Return fixed view names and pass data through the model.
- FreeMarker: set
ALLOWS_NOTHING_RESOLVER, disable?api, and use a restricted object wrapper (openEQUELLA’s fix). - Patch the engine. Thymeleaf’s restricted mode has a history of bypasses (3.1.4, 3.1.5).
- Restrict who can author templates: email, notification and portlet editors are the usual sinks.
Related
- Server-Side Template Injection · SSTI Detection · Expression Language Injection · Remote Code Execution
Sources
- PayloadsAllTheThings SSTI: Java · original
- Exploiting SSTI in Thymeleaf · original
- Exploiting SSTI in a Modern Spring Boot Application · original
- Don't Panic: The Thymeleaf Template Injection · original
- Thymeleaf sandboxed expression SSTI bypass · original
- SpringBootAdmin Thymeleaf SSTI to RCE · original
- CVE-2022-46166: Spring Boot Admin RCE · original
- CVE-2021-43466: Thymeleaf Spring5 RCE · original
- Exploiting CVE-2021-25770: SSTI in YouTrack · original
- Synack: Discovering an SSTI vulnerability in FreeMarker · original
- openEQUELLA authenticated RCE via FreeMarker SSTI · original
- OpenMetadata RCE via SSTI in FreeMarker Email Templates · original
- Apache OFBiz MacroScreenRenderer FreeMarker SSTI · original
- JetBrains TeamCity RCE via FreeMarker template injection · original
- CVE-2023-49964: FreeMarker SSTI in Alfresco · original
- CVE-2024-29178: Apache StreamPark FreeMarker SSTI · original
- GitHub Security Lab: SSTI in Apache Camel · original
- Multiple ServiceNow SSTI Vulnerabilities · original
- Atlassian Confluence Widget Connector Macro SSTI · original
- High severity SSTI advisory (Bamboo CVE-2026-21596) · original