🎄 Join our Annual Holiday wargame and win prizes!


Server Side Template Injection

Server-Side Template Injection (SSTI) occurs when untrusted input is embedded directly into a server-side template, causing the template engine to evaluate attacker-controlled expressions. This can escalate from data leakage to arbitrary code execution, depending on the template engine’s capabilities.

One of the main causes of SSTI is string concatenation of untrusted input into the template rather than passing it safely through the template context. Another common cause is double rendering, where a value is parsed and evaluated more than once, unintentionally executing injected expressions.

Remediation

  • Never concatenate untrusted input into templates — always pass it as context variables.
  • Ensure the template engine is configured to automatically escape or sandbox expressions.
  • Review and eliminate any cases of multiple rendering or re-evaluation of template content.
  • Where possible, use a simpler template engine that does not allow arbitrary code execution.

Metadata

  • Severity: critical
  • Slug: server-side-template-injection

CWEs

  • 96: Improper Neutralization of Directives in Statically Saved Code ('Static Code Injection')
  • 74: Improper Neutralization of Special Elements in Output Used by a Downstream Component
  • 94: Improper Control of Generation of Code ('Code Injection')

OWASP

  • A03:2021: Injection
Deco line
Deco line

Play AppSec WarGames

Want to skill-up in secure coding and AppSec? Try SecDim Wargames to learn how to find, hack and fix security vulnerabilities inspired by real-world incidents.

Deco line
Deco line

Got a comment?

Join our secure coding and AppSec community. A discussion board to share and discuss all aspects of secure programming, AppSec, DevSecOps, fuzzing, cloudsec, AIsec code review, and more.

Read more