SSTI: When the Template Engine Runs Your Code

Day 7 put your input in the victim’s browser as JavaScript. Today your input runs on the server itself, as the template engine’s own language. Server-Side Template Injection, SSTI, happens when an application embeds user input directly into a template string before that template is rendered, rather than passing the input in as data the template merely displays. The engine cannot tell your input apart from the template’s own logic, so it evaluates both.
This is the fourteenth class in the series, and it sits in an unusual spot: it looks like XSS at first glance, it is confirmed the same cautious way SQLi is, and it frequently ends exactly where command injection from Day 14 ends, with a shell. Security researchers studying SSTI reports on HackerOne have specifically flagged how consistently high the severity runs for this class, since the base CVSS score for SSTI-related CVEs averages notably higher than most other injection categories, and RCE is present in a large share of them.
Inside scope only, with minimal proof. SSTI can reach full remote code execution. Confirm with a benign arithmetic expression first, escalate only as far as a single harmless command, and never pivot deeper into the server.
What SSTI actually is, and why it is not XSS
Template engines, Jinja2 and Flask in Python, Twig in PHP and Symfony, FreeMarker and Velocity in Java, Handlebars in JavaScript, exist so developers can mix static HTML with dynamic values using a simple syntax, typically double curly braces or similar delimiters.
Hello {{ name }}, welcome back!
The engine substitutes name with the actual value at render time. The vulnerability appears when a developer, instead of passing user input in as a variable to be substituted, concatenates it directly into the template string itself, before that string is ever handed to the rendering engine.
# vulnerable pattern
template = "Hello " + user_input + ", welcome back!"
return render_template_string(template)
If user_input is a normal name, nothing unusual happens. If user_input is {{7*7}}, the engine does not see a name at all. It sees a template containing an expression, and it evaluates that expression, because from the engine’s point of view, it was asked to render exactly that.
The critical distinction from XSS: XSS payloads run in the victim’s browser, and the server never does anything with them beyond storing and forwarding text. SSTI payloads run on the server, inside the template engine’s own expression language, which in many engines is powerful enough to reach the underlying programming language’s objects, modules, and eventually, the operating system itself. That is why SSTI frequently escalates to full remote code execution where XSS, on its own, cannot.
Detecting it: the math trick, and why it works
The standard first probe for SSTI is deceptively simple.
{{7*7}}
${7*7}
<%= 7*7 %>
#{7*7}
If any of these renders back as 49 rather than the literal text you sent, the input is being evaluated as a template expression, not displayed as plain data. This single test is the entire detection phase for SSTI, and it is also exactly why the bug is easy to overlook during casual testing: a normal name field returning a normal name looks completely fine until you deliberately send something that looks like template syntax.
Different delimiters hint at different engines. {{ }} suggests Jinja2, Twig, or Django. ${ } suggests FreeMarker or Velocity-family engines. <%= %> suggests ERB or JSP-style engines. Getting this right early narrows which exploitation payload you try next, since each template language’s actual expression syntax for reaching dangerous functionality differs significantly.
From confirmation to RCE, engine by engine
Once {{7*7}} confirms injection, the next step is identifying the specific engine, since the path from confirmed injection to code execution is different for each one. This is the part of SSTI that rewards actually understanding the underlying language, not just copying one payload.
Jinja2 (Python, Flask). Jinja2’s sandboxing is incomplete by design, and the classic escalation walks up the Python object hierarchy from a seemingly harmless object to reach the os module:
{{ cycler.__init__.__globals__.os.popen('id').read() }}
This exact payload, using the built-in cycler object as a starting point to reach __globals__ and from there the os module, appears directly in publicly documented SSTI advisories and is one of the most reliable Jinja2 RCE payloads in circulation, precisely because cycler is present in Jinja2’s global namespace by default in many configurations.
Twig (PHP, Symfony). Twig has historically supported a _self reference that, combined with its filter and function registration system, can be abused through the filter or map constructs to reach PHP’s native functions, depending on the specific version and sandboxing configuration in place, which is exactly the root cause behind the 2024 critical WPML WordPress plugin disclosure, where shortcode content rendered through Twig without proper sanitization led directly to RCE across roughly one million affected sites.
FreeMarker and Velocity (Java). Both expose enough of the Java object model through their expression languages to instantiate arbitrary classes, and from there reach Runtime.getRuntime().exec(), Java’s standard command execution entry point, a pattern well documented across multiple CVEs in Java-based web frameworks.
Handlebars (JavaScript). Normally considered “logic-less” and safer by design, but disclosed research, including a widely referenced Shopify app finding paid $10,000, showed that Handlebars template injection in a specific app context could still be escalated to full RCE by abusing helper registration and prototype access patterns, a reminder that “logic-less” is a design intention, not an unconditional guarantee.
Real disclosed reports
- Glovo, SSTI on the name parameter during sign-up, HackerOne report #1104349, high severity, 22 upvotes. Reported by researcher battle_angel, this flaw let an attacker inject native template syntax directly through the name field collected during account registration, demonstrating how an apparently harmless profile field, exactly the kind of input that looks safe because it is “just a name,” became a direct path to server-side code execution.
- Shopify partner app, Handlebars template injection leading to RCE, $10,000 bounty. Extensively documented in a widely shared writeup, this report showed an SSTI vulnerability in a Shopify app’s use of Handlebars templating, escalated to remote code execution, and is specifically called out in security newsletters as an exemplary writeup for how to pursue an SSTI finding on an initially unfamiliar template engine all the way to a working RCE proof.
- WPML WordPress plugin, critical SSTI via Twig in shortcode rendering, affecting roughly 1 million websites, disclosed by researcher stealthcopter. The plugin rendered shortcode content through Twig templates without properly sanitizing user-supplied input first, allowing server-side template injection that could be escalated toward remote code execution, one of the most widely impactful SSTI disclosures in recent WordPress plugin history given the installation base involved.
- Kimai time-tracking software, critical SSTI escalating to RCE, tracked under CWE-1336. A more recent open-source application finding, demonstrating that SSTI is not confined to legacy codebases or only the largest bug bounty programs, actively maintained, modern applications continue to reintroduce this exact mistake.
- Spring Boot, SSTI-based Akamai WAF bypass leading to RCE, disclosed by researcher Peter M with assistance from Synack pentester Usman Mansha during a private Bugcrowd engagement. This case is particularly instructive because the SSTI was not the direct target. Vulnerable Spring Boot configurations rendered error messages through a Spring Expression Language, SpEL, context on whitelabel error pages, and the researcher specifically used this SSTI pathway to bypass a web application firewall that would otherwise have blocked a more conventional payload, showing that SSTI can also serve as a WAF evasion technique for an entirely different underlying vulnerability.
Read the Glovo report first for the cleanest, simplest example on this list, a single form field during sign-up. Then read about the Shopify Handlebars case for the most detailed engine-specific escalation writeup, and the Akamai Spring Boot bypass for how SSTI can matter even when it is not your primary target.
The variants worth knowing
Basic unsandboxed template engines. The engine has no built-in restriction at all on what expressions can reach, the Jinja2 cycler chain and the general Java reflection-based payloads both fall broadly into this category when no additional sandboxing has been configured.
Sandboxed engines with known escapes. Many modern template engines ship with a sandbox mode specifically intended to prevent exactly this kind of escalation, restricting which objects and methods an expression can reach. Security research into SSTI consistently finds that these sandboxes have a long history of documented escape techniques, meaning “the engine is sandboxed” is a reason to dig further, not a reason to stop testing.
Blind SSTI. The injected expression’s output is never reflected back to you directly, similar in spirit to the blind variants you have already learned for SQLi, SSRF, and command injection. Confirmation relies on side effects: a deliberate delay if the engine’s language supports a sleep-equivalent function reachable from the expression context, or an out-of-band callback if the reachable functionality allows making a network request.
Client-side template injection, a related but distinct bug. Some JavaScript templating libraries evaluate expressions in the browser rather than on the server. This produces a different impact profile, closer to XSS since it executes in the victim’s browser rather than on the server, and is worth knowing exists specifically so you do not misclassify or under-report it as full SSTI when the actual execution context is client-side.
Where to look, pointed at your recon
- Any field that gets reflected back into a rendered page, email, or generated document. Profile fields, display names, comments, support ticket subjects, exactly the Glovo sign-up name field case above.
- Error pages and diagnostic output, since the Spring Boot case shows that error message rendering paths are a frequently overlooked template injection surface, not just obvious user-facing content fields.
- Email templates and notification systems, where a user-controlled value, a name, a custom message, an order note, often gets inserted into a template used to generate an email server-side.
- PDF and document generation features, since many of these are built on exactly the same template engines, with user input frequently flowing into the generated document’s content.
- Any third-party plugin, theme, or app framework the target uses that relies on a known template engine, surfaced through your JS file analysis or technology fingerprinting from earlier recon, since the WPML and Shopify app cases above both originated in exactly this kind of plugin or app layer rather than core application code.
How to hunt it, step by step
Step 1: find every reflected input. List every field whose value you can influence and that later appears somewhere in the rendered output, an email, a page, a generated document, an error message.
Step 2: probe with the universal math test. Submit {{7*7}}, ${7*7}, <%= 7*7 %>, and #{7*7} across each candidate field, and check whether any renders back as 49.
Step 3: identify the specific engine from the syntax that worked, and from any other fingerprinting clues. Response headers, error messages, and known technology stack details from recon all help narrow this down.
Step 4: escalate using the engine-specific payload for that identified engine. Use the Jinja2 global-object chain, the Twig filter or sandbox escape relevant to the detected version, or the Java reflection-based approach for FreeMarker or Velocity, rather than guessing generically.
Step 5: if direct output is not reflected, test blind confirmation. A sleep-equivalent expression if the engine’s underlying language supports one reachable from the sandbox, or an out-of-band callback if outbound network access is reachable from the expression context.
Step 6: prove execution with the smallest possible command. id or whoami output through the identified engine’s command execution path is sufficient, exactly like the confirmed RCE example payload shown earlier in this post.
Writing the SSTI report
Title: Server-Side Template Injection in [parameter/field] at [endpoint] allows remote code execution
Summary:
One sentence: which field, which template engine identified, and
whether the proof shown is arithmetic confirmation only or full
command execution.
Steps to Reproduce:
1. Submit [{{7*7}} or engine-appropriate syntax] in [parameter].
2. Observe the response contains [49] rather than the literal
input, confirming template evaluation.
3. Submit [engine-specific escalation payload] in the same field.
4. Observe [command output] confirming remote code execution.
(Exact payloads for each step, response showing the evaluated
arithmetic and the command output, and the identified template
engine and version if determinable.)
Impact:
User input is evaluated as template expression syntax rather than
treated as plain data, allowing [arithmetic evaluation / full
remote code execution] under the privileges of the application
process. State the realistic worst case, full server compromise
if RCE was demonstrated.
Remediation:
Never concatenate user input directly into a template string
before rendering; always pass user input in as a variable for
the template to merely display, using the engine's intended data
binding mechanism rather than string construction. Where dynamic
template content from users is genuinely required, use the
engine's sandboxed rendering mode and keep it updated, since
sandbox escapes are routinely discovered and patched.
Strong SSTI reports, the Glovo and Shopify cases especially, clearly separate the initial confirmation step, the harmless arithmetic result, from the escalation step, and name the specific engine and payload chain used for each, which is exactly what lets a triager quickly verify severity without needing to reconstruct the exploitation path themselves.
What programs often reject
- Arithmetic confirmation alone with no attempt made to identify the engine or escalate further, on programs that explicitly expect a demonstrated RCE or data access impact for this class
- Client-side template injection findings reported and rated as if they were full server-side RCE, when the actual execution context was the browser
- Findings against a template engine explicitly documented as rendering only pre-approved, developer-authored templates with no user-controlled template string ever reaching it
- Reports where a webshell or persistent payload was left running past the point needed to demonstrate the finding
The mindset: a template engine is an interpreter, and interpreters execute
This closes the loop the series has walked through since Day 6. SQL, JavaScript, a shell, an XML parser, and now a template engine, are all interpreters that execute whatever expression syntax they recognize, with no inherent way to tell “the part the developer wrote” from “the part a user supplied,” unless the boundary between the two was deliberately and correctly enforced. SSTI is simply this same lens pointed at the one interpreter most developers forget is an interpreter at all, because it mostly just prints text.
Homework for Day 16
- From recon, list every field that gets reflected back into a rendered page, email, generated document, or error message.
- Test the universal math probe,
{{7*7}} and its variants, across every candidate field.
- Where injection is confirmed, identify the specific template engine from the syntax that worked and any available fingerprinting clues, then research that engine’s known escalation path.
- Attempt the engine-specific escalation payload to reach command execution, proving it with a single minimal command.
- Read the Glovo SSTI report (hackerone report #1104349) end to end, then read about the Shopify Handlebars RCE case. For each, note how the researcher moved from initial confirmation to a working RCE payload, and how the report framed severity at each stage.
A confirmed SSTI with only arithmetic evaluation demonstrated is typically a valid medium or high severity finding on its own, and one escalated to remote code execution is almost always critical. Document it with the specific engine identified, the exact escalation payload chain, and the data-binding remediation rather than string concatenation.
Day 17 moves to a bug where the application trusts a header it should never have trusted in the first place, Host Header Injection, and how it quietly powers password reset poisoning and cache poisoning attacks.