# 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 `path` example 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_abc` to 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 - [[raw/github.com/payloadsallthethings-ssti-java-3865|PayloadsAllTheThings SSTI: Java]] - [[raw/acunetix.com/exploiting-ssti-in-thymeleaf-4139|Exploiting SSTI in Thymeleaf]] - [[raw/modzero.com/exploiting-ssti-in-a-modern-spring-boot-application-4140|Exploiting SSTI in a Modern Spring Boot Application]] - [[raw/snyk.io/don-t-panic-the-thymeleaf-template-injection-that-only-hurts-if-you-le-8722|Don't Panic: The Thymeleaf Template Injection]] - [[raw/github.com/thymeleaf-sandboxed-expression-ssti-bypass-13370|Thymeleaf sandboxed expression SSTI bypass]] - [[raw/github.com/springbootadmin-thymeleaf-ssti-to-rce-4138|SpringBootAdmin Thymeleaf SSTI to RCE]] - [[raw/sangfor.com/cve-2022-46166-spring-boot-admin-rce-4127|CVE-2022-46166: Spring Boot Admin RCE]] - [[raw/security.snyk.io/cve-2021-43466-thymeleaf-spring5-rce-4128|CVE-2021-43466: Thymeleaf Spring5 RCE]] - [[raw/synacktiv.com/exploiting-cve-2021-25770-ssti-in-youtrack-synacktiv-4579|Exploiting CVE-2021-25770: SSTI in YouTrack]] - [[raw/synack.com/synack-discovering-an-ssti-vulnerability-in-freemarker-3861|Synack: Discovering an SSTI vulnerability in FreeMarker]] - [[raw/github.com/openequella-authenticated-rce-via-freemarker-ssti-13770|openEQUELLA authenticated RCE via FreeMarker SSTI]] - [[raw/github.com/openmetadata-rce-via-ssti-in-freemarker-email-templates-3485|OpenMetadata RCE via SSTI in FreeMarker Email Templates]] - [[raw/github.com/apache-ofbiz-macroscreenrenderer-freemarker-ssti-to-rce-cve-2026-82910-13602|Apache OFBiz MacroScreenRenderer FreeMarker SSTI]] - [[raw/github.com/jetbrains-teamcity-rce-via-freemarker-template-injection-15367|JetBrains TeamCity RCE via FreeMarker template injection]] - [[raw/github.com/cve-2023-49964-freemarker-ssti-in-alfresco-3858|CVE-2023-49964: FreeMarker SSTI in Alfresco]] - [[raw/openwall.com/cve-2024-29178-apache-streampark-freemarker-ssti-4137|CVE-2024-29178: Apache StreamPark FreeMarker SSTI]] - [[raw/securitylab.github.com/github-security-lab-ssti-in-apache-camel-cve-2020-11994-3859|GitHub Security Lab: SSTI in Apache Camel]] - [[raw/censys.com/multiple-servicenow-ssti-vulnerabilities-4146|Multiple ServiceNow SSTI Vulnerabilities]] - [[raw/exploit-db.com/atlassian-confluence-widget-connector-macro-ssti-exploitdb-4576|Atlassian Confluence Widget Connector Macro SSTI]] - [[raw/github.com/high-severity-ssti-advisory-15162|High severity SSTI advisory (Bamboo CVE-2026-21596)]]