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-08-01. Synthesized from 99 of 99 curated resources. Browse all 99 SSTI resources →

Problem Framing

Server-Side Template Injection (SSTI) is a critical web security vulnerability that allows an attacker to inject malicious code into server-side templates, leading to arbitrary code execution on the server [1][2][3][4][5][6]. This occurs when applications improperly handle user input that is then processed by a templating engine. The primary danger of SSTI lies in its potential to grant attackers Remote Code Execution (RCE), enabling them to compromise the entire server, steal sensitive data, or disrupt services [1][2][3][4][5][6]. Unlike Cross-Site Scripting (XSS), which impacts the client-side browser, SSTI directly targets the server's runtime environment [7][8].

Template engines are ubiquitous in modern web development, used to dynamically generate content such as HTML pages, emails, and reports by embedding placeholders for variables and logic within static templates [1][7][2][4][5]. Examples of popular engines include Jinja2 (Python), Twig (PHP), FreeMarker (Java), ERB (Ruby), and Handlebars (JavaScript) [7][8][9][10]. The vulnerability arises when user-supplied data is treated as executable template code rather than inert data [1][7][3][5]. This can happen when developers directly concatenate user input into template strings or use functions like render_template_string() in Flask without proper sanitization or context separation [1][3][11][12][13][14].

The impact of SSTI can range from information disclosure (e.g., configuration files, sensitive keys) to complete server compromise, depending on the template engine's capabilities and the application's security posture [1][2]. The severity is often critical due to the potential for RCE [1][2][3][4].

Core Mechanics

SSTI vulnerabilities are fundamentally about the unsafe interpretation of user-controlled input within a templating engine's parsing and rendering process. The core mechanism involves tricking the template engine into evaluating data provided by an attacker as executable code or template directives.

At a high level, the exploit process follows these stages:

  1. Identify Input Points: Locate any part of the application where user input is reflected in the server's response and might be processed by a template engine. This could be URL parameters, form fields, HTTP headers, or even data embedded in less obvious places like email templates [4][15][10].
  2. Detect Template Injection: Inject basic template syntax or mathematical expressions to see if they are evaluated by the server. Common indicators include seeing the result of an arithmetic operation (e.g., {{7*7}} rendering as 49) or specific error messages that reveal the template engine in use [7][4][15][10]. Polyglot payloads, which combine syntax from multiple engines, can be useful for initial detection [16][15][17][9][18].
  3. Identify the Template Engine: Different engines use distinct syntaxes and have varying capabilities. Recognizing the engine (e.g., Jinja2, Twig, FreeMarker) is crucial for crafting effective payloads [7][8][16][15][10]. Error messages are often a good source for identifying the engine.
  4. Explore the Sandbox and Attack Surface: Once injection is confirmed, the attacker explores the available objects, variables, and functions exposed by the template engine and its context. This often involves inspecting built-in objects like config, request, or self in Jinja2, or using reflection-based techniques in Java environments [19][3][11][20][21][13][22][23][24][25][10].
  5. Achieve Code Execution: The ultimate goal is typically RCE. This is achieved by finding a way to access modules like os or subprocess (in Python) or java.lang.Runtime (in Java) to execute arbitrary operating system commands or code [1][3][11][5][21][13][25][10].

The core mechanics rely on the template engine's ability to access and manipulate objects and execute functions. When user input is directly interpolated into template syntax, it can bypass intended data rendering and trigger code execution paths. For instance, Jinja2's ability to access object attributes via __init__.__globals__ or __class__.__mro__ allows navigation of Python's class hierarchy to reach sensitive modules [19][3][11][21][13][23][24][25]. Similarly, Java template engines might expose reflection capabilities or specific utility classes like freemarker.template.utility.Execute that can be abused for RCE [20][26][27][28].

Notable Techniques

Exploiting SSTI vulnerabilities often involves sophisticated techniques to navigate the template engine's environment and bypass security controls. The methods vary significantly based on the template engine and the application's specific implementation.

Jinja2 (Python)

Jinja2 is a prevalent engine in Python web frameworks like Flask. Exploitation often targets its ability to access Python's internal objects and execute arbitrary Python code [19][3][11][21][13][23][24][25][10].

{{ self.__init__.__globals__.__builtins__.__import__('os').popen('id').read() }}

[19][29]

Twig (PHP)

Twig, common in PHP applications like Symfony, also allows for RCE, often through similar methods as Jinja2 or by exploiting specific Twig features [32][33][13][34][35][9][18].

{{_self.env.registerUndefinedFilterCallback("system")}}{{_self.env.getFilter("id")}}

[7][34]

FreeMarker (Java)

FreeMarker is widely used in Java applications. Exploiting it typically involves leveraging Java's reflection capabilities or specific utility classes [20][38][13][39][26][27][28][10].

<#assign ex="freemarker.template.utility.Execute"?new()> ${ex("id")}

[38][39]

ERB (Ruby)

ERB is Ruby's default templating engine. Exploitation often involves direct code execution via Ruby syntax or accessing controller/server objects [1][42][43][44][45][17][10].

<%= system('id') %>

[1][42][43][45][17]

Other Template Engines

#set($x = $class.inspect("java.lang.Runtime")) ${x.getRuntime().exec("id")}

[28]

General Exploitation Techniques

Detection & Prevention

Detecting and preventing SSTI requires a multi-layered approach, focusing on both secure coding practices and diligent security testing.

Detection Strategies

Prevention Measures

Tooling

Several tools are instrumental in the detection, identification, and exploitation of SSTI vulnerabilities.

Recent Developments

The SSTI landscape is continually evolving, with new research highlighting sophisticated bypass techniques and vulnerabilities in emerging technologies.

Where to Go Deeper

For practitioners looking to deepen their understanding and practical skills in SSTI, the following resources provide invaluable insights:

Understanding the nuances of different template engines, their security models, and common exploitation patterns is crucial for effective SSTI testing and defense.

Sources cited in this guide

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