[Templates] — Exploiting PugJS Server-Side Template Injection to Remote Shell Access
A web application rendered user-supplied Pug templates without proper separation of data and logic, allowing server-side template injection. An attacker could execute arbitrary JavaScript on the server and escalate to a reverse shell, gaining user-level access.
meetcyber.net
Published on meetcyber.net
Server-Side Template Injection (SSTI) is a class of vulnerability where user-controlled input is embedded directly into a server-side template and evaluated as code.
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 passed user input directly into Pug template compilation without sanitisation, so template expressions were evaluated as server-side JavaScript.
Impact
An attacker could execute arbitrary commands on the server and obtain an interactive shell with user-level privileges, potentially leading to deeper compromise.
What the attacker needed
Access to a feature that renders Pug templates; ability to send outbound connections from the target
How it was found
- Access the feature that converts Pug templates into rendered HTML.
- Test a generic template injection polyglot inside an HTML <p> tag; the server reflects it as raw HTML without evaluation.
- Switch the injection point from a standard HTML tag to a Pug-specific identifier (#), causing a template rendering error.
- Test a simple Pug interpolation payload to confirm server-side evaluation.
- Attempt to execute a payload to read user account information; the server returns <undefined>.
- Start a local HTTP listener and trigger a curl request from the target to verify outbound connectivity.
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 report about a web app that lets you write template code (Pug) and see the result. Because the app actually runs that code on its server, an attacker can make the server run commands of their choosing, like opening a shell. That gives the attacker control 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.