What Is Server-Side Template Injection (SSTI)?

On this page
  1. How does SSTI arise?
  2. Why is SSTI so dangerous?
  3. How do you prevent it?

Server-side template injection (SSTI) happens when user input is placed into a server-side template that the engine then evaluates — instead of being passed safely as data into a pre-written template. Because template engines can run expressions and reach into application objects, attacker-controlled template syntax frequently escalates to reading secrets or full remote code execution on the server.

How does SSTI arise?#

The mistake is building the template itself from user input:

Dangerous:  render_template_string("Hello " + user_name)
Input:      {{ 7 * 7 }}
Rendered:   Hello 49     ← the engine evaluated the input

That 49 is the tell: the engine executed the expression. From there, attackers navigate the template language to reach objects that run system commands. Contrast the safe pattern, where the template is fixed and input is only ever data passed into it.

Why is SSTI so dangerous?#

Because template engines are powerful by design. Unlike XSS, which runs in a browser sandbox, SSTI runs on the server with the application’s privileges:

XSSSSTI
Executes onVictim’s browserThe server
Typical worst caseSession theft, actionsRemote code execution
Root causeInput into HTMLInput into a template

How do you prevent it?#

  • Never build templates from user input — keep templates static; pass input as bound data only.
  • Use logic-less or sandboxed templates where feasible.
  • Treat template syntax like code — the same discipline as parameterizing SQL.

SSTI is injection aimed at the template layer, a cousin of command injection. More at the Web Security hub.

Frequently asked questions#

What is server-side template injection?

SSTI occurs when user input is embedded directly into a server-side template that the engine then evaluates, rather than being passed as data to a pre-written template. Because template engines can execute expressions and access objects, attacker-controlled template syntax can often escalate to reading data or full remote code execution.

How is SSTI different from XSS?

XSS executes in the victim’s browser; SSTI executes on the server, inside the template engine. SSTI is usually more severe because it can lead to server-side code execution and data access, not just actions in a user’s session. Both stem from mixing untrusted input with a language that gets evaluated.

Sources & further reading