SSTI Explained: Server-Side Template Injection for Bug Bounty Beginners


Some of the highest-paying bug bounty reports start with a strangely simple test: type {{7*7}} into a website’s input field and see if the page answers 49. If it does, you may have found Server-Side Template Injection (SSTI) — a bug that can escalate from a curious output to remote code execution on the server.

What templates are

Modern web apps do not hand-write every page. They use template engines — Jinja2 in Python, Twig in PHP, Freemarker in Java — that mix fixed page structure with dynamic data. A template looks like: Hello, {{ username }}! The engine replaces {{ username }} with the actual name. That is normal and safe — when the data is treated as data.

When it breaks

SSTI happens when user input is placed inside the template itself, not passed in as data. Imagine a greeting page built by inserting user input directly into the template string and then rendering it. If a user types {{7*7}}, the engine sees it as template code and evaluates it: 7 times 7 is 49, so the page says "Hello, 49!" The input was executed, not displayed. That is the vulnerability.

Testing for it — legally

Only test programs you are authorized to test: bug bounty scopes, your own apps, or lab apps. The classic detection test is a harmless math probe.

  • Enter {{7*7}}. If the output is 49, the input is being evaluated as a template expression.
  • If you see {{7*7}} echoed back unchanged, the input is treated as plain text — not vulnerable, at least through that field.
  • Try ${7*7} and #{7*7} too: different engines use different syntax, and the one that returns 49 tells you which engine you are dealing with.

Never go further on a target you do not have permission to test, and never use SSTI to read files or run commands outside an authorized scope.

Why it escalates

Template engines expose more than math. In many engines, a crafted payload can walk from the template object to the application’s internals — reaching classes, functions, and eventually operating system commands. That path, from {{7*7}} to full remote code execution, is why SSTI reports pay well: the impact is not a funny number on a page, it is server takeover.

How to tell it apart from XSS

SSTI and cross-site scripting look similar — both involve injecting syntax into a page — but they run in different places. XSS executes in the victim’s browser. SSTI executes on the server. The {{7*7}} test distinguishes them: XSS payloads need a browser to run, while SSTI answers come back in the server’s own response.

The fix, for developers

  • Never build templates from user input. Pass user data as variables to a fixed template.
  • If a feature genuinely needs user-supplied templates, use a sandboxed engine with dangerous features disabled, and treat that as a high-risk feature requiring review.
  • Keep template engines updated — sandbox escapes are patched regularly.

Reporting it well

A strong SSTI report shows the exact input, the exact output, the engine identified, and the impact demonstrated safely within scope — for example, a harmless command output proving code execution, not a destructive one. Include the fix suggestion above. Reports that prove impact without causing damage get paid fastest.

Start in a lab: spin up a vulnerable template app locally, try the {{7*7}} probe, and watch a template engine do exactly what it was told. Then take that understanding to authorized bounty programs. Only test systems you own or have written permission to test.

Comments

Popular Posts