Introduction

<aside> ✍️

SSTI ( Server-Side Template Injection ) → Its a web vulnerability that happens when an application merges user input directly into a server-side template that the engine then evaluates as code, instead of passing that input safely as data.

</aside>

Templates engines exists to merge data into a page, for example when setting a variable {{ name }} that server then dynamically adjust with proper data, because it treats it as code. That means that if user can control not only the value dropped into the filling, but the string itself, he could execute his own code instead.

render_template_string("Hello " + user_input) 
// instead of 
render_template("hello.html", name=user_input)

Mostly effected engines are :

Lets first deep into more technical step, CVE and CWE scores and detection, before getting into payloads and attack patterns.

Reference:


SSTI vs SSRF vs XSS

SSTI , due to its nature, is often mistaken for XSS vulnerability instead, because both start from some sort of user input. However they’re far from the same → XSS is bounded by user’s browser and SSTI runs code on the server instead.

In case of its cousin, SSRF, the attack pattern is the difference. SSTI attacks the server by using injection techniques via templates, however SSRF works by forcing the server to make request ( unauthorized ) to internal or external sources.

NOTE!: There is also client-side template injection ( CSTI ), where the vulnerable engine ( Angular, Vue, and similar ) runs in the browser. The quick way to tell them apart : re-request the input with a non-browser client such as curl. If 49 appears in the raw HTTP response body, it is server-side ( SSTI ); if it only appears in the rendered DOM after JavaScript runs, it is client-side ( CSTI ).


Detection - How Do You Find It?

Following official documentation of OWASP Web Security Testing Guide, we can follow three stages :

First we detect, for example using polyglots. We inject string with special characters, drawn from many template syntaxes at once, like ${{<%[%'"}}%\ into every input, which ends up rendered. If it returns any sort of error, like expection or 500, instead of echoing the string literally, it means it processed the string literally.

Detect

Now we check for two possible contexts, because SSTI comes in two forms, each with its own check:

Identify