All vulnerabilities
CRITICALAppSecexploited in the wild

APPSEC-SSTI

Web app · Server-Side Template Injection

Summary

Server-side template injection occurs when user input is concatenated into a template that is then evaluated by a server-side engine, so the input is parsed as template directives rather than data; because engines like Jinja2, Twig, FreeMarker, and Velocity expose object introspection, a payload such as {{7*7}} returning 49 confirms evaluation, and attackers then walk the object graph (for example Jinja2's class/mro/subclasses chain or Java reflection in FreeMarker) to reach runtime classes and achieve remote code execution. It maps to OWASP A03:2021 Injection (CWE-1336 / CWE-94). The vulnerability class was formalized and named by James Kettle of PortSwigger in his Black Hat USA 2015 research 'Server-Side Template Injection: RCE for the Modern Web App,' which demonstrated automated detection and engine-specific SSTI-to-RCE exploitation, and it has since produced numerous documented bug-bounty RCE findings against major applications.

How to avoid it in your code

  • Never pass user input as part of the template source; pass it only as bound template variables/context data.
  • Render untrusted content as data, not as templates, so it is escaped rather than evaluated.
  • Use a sandboxed or logic-less engine (e.g. Mustache, Jinja2 SandboxedEnvironment) for any user-influenced templates.
  • Restrict the template context to remove access to dangerous objects, builtins, and reflection.
  • Run rendering in a least-privilege, isolated process to contain any successful injection.

References

Related vulnerabilities

All AppSec →