Web Security Series #18 — Exploiting Server-Side Template Injec
A lab application echoed user input through the Twig template engine without sanitising it, so injected template expressions were evaluated on the server. The author confirmed this by getting an arithmetic expression to render as its result and then ran a system command, achieving code execution as the web server user.
Published on medium.com
Modern web applications frequently rely on template engines to dynamically render user content. While these engines improve development efficiency, improper handling of user input can introduce critical vulnerabilities.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the application embedded user-supplied input directly into a server-side Twig template and rendered it, instead of treating it as plain data.
Impact
An attacker could execute arbitrary system commands on the server, which the author says could lead to full server compromise and data leakage.
What the attacker needed
A lab application with a message field; Burp Suite for intercepting requests
The fix
User input should not be rendered as raw template code; it should be passed as data, with strict validation and sandboxing of the template engine.
How it was found
- Submit a simple message and observe it is echoed back on the page.
- Capture the POST request containing the message in Burp Suite and send it to Intruder.
- Fuzz the message parameter with a payload list and sort responses by length to spot the template engine name.
- Submit a basic Twig arithmetic expression and check the page source to confirm the result was computed on the server.
- Submit a Twig payload that calls a system function to run a command and observe the output.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A template engine is a tool a website uses to build pages by filling in placeholders. Here the site put whatever the visitor typed straight into that template, so the visitor could type template code instead of plain text and the server would run it. That let the author run a system command on the server.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.