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:

EngineRCE-relevant surfaceHardening 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
ThymeleafVariable expressions evaluated as SpEL/OGNL; expression preprocessing __${...}__; user-controlled view names / fragment paths in Spring MVCThymeleaf 3.1 restricted-expression denylist (bypassed repeatedly)
VelocityReflection via exposed objects ($class-style access)SecureUberspector
Pebble / JinjavaMethod calls on context objects, dynamic class loadingmethod 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

ProductIDNotes
ServiceNowCVE-2024-4879, -5178, -5217Jelly template injection, unauth RCE chain; CISA KEV; mass recon campaign
Atlassian ConfluenceCVE-2019-3396Widget Connector: uploaded Velocity template
Atlassian Bamboo DCCVE-2026-21596authenticated SSTI → command exec (12.0.0–12.1.x)
Apache OFBizCVE-2026-82910MacroScreenRenderer link params concatenated into FreeMarker
JetBrains TeamCity<2026.2.2 / <2026.1.6FreeMarker injection RCE
JetBrains YouTrackCVE-2021-25770FreeMarker sandbox bypass
AlfrescoCVE-2023-49964FreeMarker in folder.get.html.ftl; builds on CVE-2020-12873
Apache StreamParkCVE-2024-29178FreeMarker, authenticated
Apache CamelCVE-2020-11994template header / resource URI control (FreeMarker, Velocity, MVEL, Mustache)
openEQUELLA<2026.1.0permissive FreeMarker defaults (?new(), ?api)
OpenMetadataGHSA-5f29-2333-h9c7admin-editable FreeMarker email templates
Spring Boot AdminCVE-2022-46166Thymeleaf sandbox bypass via notifier template
Thymeleaf Spring5CVE-2021-43466AjaxThymeleafView 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.

Sources