Server-side Template Injection with Information Disclosure via User-Supplied Objects in Django Framework (Python)
A Django template injection vulnerability allowed an attacker to inject template expressions and access server-side objects, leading to disclosure of the framework's secret key. The attacker could retrieve sensitive configuration data and potentially escalate to full system compromise.
Published on bashoverflow.com
This lab demonstrates a server-side template injection (SSTI) vulnerability that occurs when user-controlled input is passed directly into a server-side template engine without proper sanitization. In this case, an object provided by the user is embedded into the template.
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, user-controlled input was passed directly into the Django template engine without proper sanitisation, allowing template expressions to be evaluated.
Impact
Attackers could access environment variables or secret keys, leading to a complete breach of confidentiality and potential full system compromise.
What the attacker needed
Valid credentials for content-manager; access to edit article templates
How it was found
- Log in with the provided credentials.
- Navigate to a sample article and choose to edit the template.
- Insert a polyglot payload to test for template injection.
- Inject a debug statement to display internal variables and settings.
- Modify the payload to extract the secret key.
- Copy the leaked key and submit it to solve the lab.
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.
This is a server-side template injection (SSTI) bug. When a website lets users put special template code into a page, attackers can trick the server into running their own template commands. Here, that let the attacker read the secret key, a password-like string that protects the site.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.