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

Problem Framing

Server-Side Template Injection (SSTI) occurs when untrusted user input is incorporated into server-side templates without proper validation or sanitization, allowing an attacker to inject and execute malicious code on the server [1][2][3][4][5][6][7][8][9][10]. Unlike client-side vulnerabilities like Cross-Site Scripting (XSS), where malicious code executes in the user's browser, SSTI payloads are processed and executed by the template engine on the server itself [1][11]. This fundamental difference in execution context grants SSTI a significantly broader blast radius, potentially leading to information disclosure, arbitrary file access, privilege escalation, and most critically, Remote Code Execution (RCE) [1][2][12][6][7][8].

Template engines are ubiquitous in modern web development, used for generating dynamic content such as HTML, emails, configuration files, and reports. They separate presentation logic from application code, allowing developers to create reusable components and manage dynamic data efficiently [2][12][6]. Common examples include Jinja2 (Python), Twig (PHP), FreeMarker (Java), Velocity (Java), Handlebars (JavaScript), Pug (Node.js), and ERB (Ruby) [1][2][11][3][4][13][7][14][8][15][9]. The very nature of these engines, designed to interpret and execute expressions within templates, makes them susceptible to injection if user-controlled data is treated as template code rather than plain data [1][11][3].

The root cause of SSTI lies in how user input is handled. Securely, user input is passed as data to a pre-defined, trusted template. Insecurely, user input is directly concatenated or interpolated into the template string, becoming part of the template code itself [1][2][11]. This distinction is critical:

The impact of SSTI can be severe, ranging from sensitive information disclosure (e.g., configuration files, credentials) to complete server compromise through RCE [1][12][5][6][8][16][10]. Due to their potential for high impact and the widespread use of template engines, understanding SSTI is crucial for application security professionals [11][12][5][6].

Core Mechanics

The fundamental mechanism behind SSTI is the improper handling of user-supplied input within a server-side templating engine. This leads to the template engine interpreting the input as code rather than literal data, thereby executing arbitrary logic on the server [1][2][3][8].

The process generally follows these stages:

1. Input Vector Identification

The first step is to identify input fields or parameters that are reflected in the server's response and appear to be processed by a template engine [1][11][5][14][17][10]. This can include:

2. Template Engine Detection

Once a potential injection point is found, the next critical step is to identify the specific template engine in use. Different engines have distinct syntaxes and object models, which dictate the available exploitation techniques. A common method for detection is to submit basic mathematical expressions within the expected template syntax. If the server evaluates the expression and returns the result (e.g., 49 for 7*7), it confirms that the input is being processed as code [1][11][3][5][21][7][14][8][22][17][10].

Different template engines use characteristic delimiters:

By using a "polyglot" payload that mixes delimiters from various engines, or by observing error messages when submitting invalid syntax, one can often infer the engine. For instance, {{7*'7'}} might result in 7777777 for Jinja2/Twig but 49 for Mako [1][11][23][8]. Error messages themselves can also be invaluable, often revealing the template engine's name and version [1][11].

3. Payload Construction and Exploitation

Once the template engine is identified, the attacker crafts a payload to achieve their objective, typically RCE. This involves understanding the engine's object model, available functions, filters, and how to navigate through inherited classes to find executable code or sensitive information [1][11][3][5][7][8][26][27]. The goal is to reach objects or functions that can interact with the operating system, such as Python's os module, Java's Runtime class, or PHP's system() function [1][11][5][7][8][26][27].

Exploitation often involves:

4. Blind SSTI

In scenarios where direct output is not reflected, blind SSTI techniques are employed. These rely on observing indirect effects, such as time delays (Time-Based SSTI) or conditional errors (Error-Based or Boolean-Based SSTI) to infer the success of a payload [4][49][5][23][8][20][22][27]. For example, using a sleep(10) command in a payload and measuring the server's response time can confirm vulnerability [20].

Notable Techniques

The exploitation of SSTI vulnerabilities is highly dependent on the specific template engine and its configuration. However, several common techniques and approaches have emerged for detecting and exploiting these flaws across various platforms.

1. Basic Detection and Identification Payloads

The initial step in identifying SSTI is to use simple payloads that test for template engine evaluation. Mathematical expressions are a common and effective choice because their results are unlikely to appear coincidentally [1][11][3][5][23][7][14][8][22][17][10].

For example:

If the response shows 49, it indicates server-side evaluation. Further probes like {{7*'7'}} can help differentiate between engines (e.g., Jinja2 vs. Twig) [1][11][23][8]. Triggering errors with invalid syntax (e.g., {{undefined_variable}} or (1/0).zxy) can also reveal the template engine's name or version [1][11][49][23][22].

2. Object Chaining for RCE

In engines like Jinja2 (Python) and Twig (PHP), much of the exploitation relies on navigating the object model to find pathways to execute code. This often involves starting from a common, accessible object and traversing its attributes and methods [1][3][4][29][7][80][31][30][26][10].

A classic Jinja2 technique involves starting from a string literal (e.g., "" or request) and using special attributes to reach the base object class, then its subclasses, and finally a class that can execute commands [1][4][29][7][31][30][26][10]:

For example, in Jinja2, to execute the id command: {{''.__class__.__mro__[1].__subclasses__()[157].__repr__.__globals__.get('__builtins__').get('__import__')('subprocess').check_output('id')}} [24]. A more stable approach uses accessible globals like cycler or lipsum: {{ cycler.__init__.__globals__.os.popen('id').read() }} [44][11][21][13][23][7][32][33][31][26].

3. Engine-Specific Execution Primitives

Each template engine provides distinct mechanisms for code execution:

4. Filter Bypasses

Web Application Firewalls (WAFs) and custom sanitization filters often blacklist dangerous characters or keywords (e.g., __, ., [, ], eval, system) [44][36][37][38][60][39][33][31][30][87]. Bypassing these filters requires obfuscation and alternative syntax:

Detection and Prevention

Detecting and preventing SSTI requires a multi-faceted approach, focusing on secure coding practices, robust input validation, and effective tooling.

1. Detection Strategies

Detecting SSTI vulnerabilities involves a combination of automated scanning and manual probing.

2. Prevention Strategies

Preventing SSTI hinges on secure development practices and robust application architecture.

Recent Developments

The landscape of SSTI is constantly evolving, with new techniques and vulnerabilities being discovered. Recent trends highlight a focus on bypassing sophisticated defenses and exploiting less common template engines or specific framework integrations.

1. Advanced Sandbox Escapes and Filter Bypasses

Attackers continue to develop sophisticated methods to bypass security sandboxes and filters designed to prevent code execution. This includes:

2. Exploitation in Specific Frameworks and Applications

Numerous recent CVEs and research papers highlight SSTI vulnerabilities within specific applications and frameworks:

3. Supply Chain and CI/CD Risks

SSTI is not limited to traditional web applications. It can also manifest in CI/CD pipelines, configuration management tools (e.g., Helm charts), and automated scripting, posing supply chain risks [45][7]. Malicious code embedded in template files within a build pipeline could lead to execution in developer environments or during software deployment [45].

Where to Go Deeper

For those seeking to deepen their understanding of Server-Side Template Injection, a wealth of resources is available, spanning academic research, practical labs, tooling, and detailed write-ups.

1. Academic and Research Papers

Formal research provides foundational knowledge and often uncovers novel techniques.

2. Comprehensive Online Resources and Write-ups

Community-driven platforms and blogs offer practical insights, exploit examples, and exploit chains.

3. Exploitation Tools

Automated tools significantly streamline the SSTI hunting process.

4. Hands-on Labs and Training

Practical experience is invaluable. Setting up local labs or participating in curated training environments allows for safe experimentation.

By engaging with these resources, practitioners can develop a deep understanding of SSTI, from fundamental principles to advanced exploitation and bypass techniques.

Sources cited in this guide

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