A simple diagram of the Server-Side Template Injection risk path
Risk path: an input or context crosses a security boundary.
A simple three-step test path for Server-Side Template Injection
Testing path: establish a baseline, make one controlled change, and verify the effect.

01Issue

Overview

A template engine combines a template with values to build a page, email, or document. Server-side template injection (SSTI) happens when user input is treated as template instructions rather than as data. For example, a user-supplied string may be evaluated by the template engine instead of being printed literally. The outcome depends on the engine, its configuration, and what data or functions the template can reach.

Common causes

  • The application concatenates user input into template source and renders the result.
  • A preview or customization feature evaluates user-controlled template expressions.
  • Users can edit templates without a restricted language or safe sandbox.
  • Template data exposes objects or helper functions that are more powerful than needed.

References: CWE-1336: Template Engine Injection ↗PortSwigger: Server-Side Template Injection ↗OWASP Code Review Guide: Template Injection ↗

02Examples

EXAMPLE

Hypothetical test: enter {{7*7}} into a template-backed display field. If the page shows 49, the renderer evaluated the expression somewhere in the flow; compare with a plain-text field and inspect server-side rendering to locate it. This confirms evaluation, not file access or command execution.

03Impact

Attacker-controlled input must reach a template renderer as template source. A displayed calculation or changed output can indicate evaluation; server-side data access or code execution requires a separate reachable capability and evidence.

A confirmed issue may alter rendered content or expose values available to the template. In some engines and configurations, access to powerful objects can lead to more serious server-side effects. Do not infer code execution merely because a template expression is evaluated; identify what the engine can access and demonstrate the impact separately.

04Testing

Test cases

1. Check whether input is evaluated by a template

Place a small arithmetic expression in a test input that is rendered by the server. Compare the response with the literal expression and a normal baseline.

Example: A result such as 49 can be a lead. Confirm the template engine and rule out client-side processing.

GET /welcome?name=%7B%7B7%2A7%7D%7D HTTP/1.1
Host: app.example.test

2. Compare template input locations and syntax

Test each relevant rendering path using expressions appropriate to the identified engine. Compare stored and reflected input without assuming all templates use the same engine.

Example: A saved notification may be rendered later by a different service. Inspect the output from that specific path.

POST /api/messages HTTP/1.1
Host: app.example.test
Content-Type: application/json
 
{"message":"{{7*7}}"}

3. Review how templates are constructed

Inspect whether untrusted data is passed as a value or concatenated into a template. Review available template features and server privileges before describing impact.

Example: Expression evaluation does not automatically prove file access or code execution. Report the behavior that was observed.

Testing references: CWE-1336: Template Engine Injection ↗PortSwigger: Server-Side Template Injection ↗OWASP Code Review Guide: Template Injection ↗

05Mitigation

Keep templates fixed and pass user values as data through the engine’s supported parameter mechanism. Do not concatenate user input into template source. If user-authored templates are a product feature, use a restricted template language, expose only necessary data, disable dangerous functions, and run rendering with limited privileges and resource bounds.

Retest

Repeat harmless expression probes in each rendering path. Confirm user text remains literal where templates are fixed and that intended user-authored features expose only documented capabilities.