How a Blind SSTI in an Email Template Engine Led to Remote Code E
An email template designer evaluated user-supplied template expressions server-side without sandboxing, so an administrator could inject Jinja2 expressions that walked Python's object hierarchy to reach a process-spawning class. This allowed arbitrary command execution on the underlying Linux host, demonstrated with a harmless identity command.
When security engineers audit web applications, template rendering engines are often treated as low-risk utilities. Developers assume templates merely handle basic string interpolation — formatting a user’s name or setting an order confirmation layout.
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 template rendering used a standard, unsandboxed Jinja2 environment, letting template input reach Python internals and a class that spawns processes.
Impact
An attacker with template access could run arbitrary commands on the application container, enabling internal network pivoting, extraction of credentials and cloud keys, and persistent access.
What the attacker needed
Administrator access to template designer
The fix
The rendering was moved to Jinja2's sandboxed environment and the service was run in an isolated, unprivileged container with a read-only file system.
How it was found
- Save a template and send a preview request with a maths expression in the body.
- Observe that the double-curly expression is evaluated to a number.
- Submit an expression that lists Python subclasses to find a process-spawning class.
- Use the found class index to run a harmless identity command and read 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 fills in placeholders like a name in an email, but some engines can also do maths and run code. Here the server ran whatever was typed into the template, so the tester could make it run system commands. That means someone with template access could take over 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.