EJS, Server side template injection RCE (CVE-2022-29078)
The EJS templating library passed user-controlled settings into the template rendering options, allowing an attacker to inject a malicious value that was executed as server-side code. An attacker could achieve remote code execution on a server that rendered a template with attacker-influenced options.
eslam.io
Published on eslam.io
Recently i was working on a related project using one of the most popular Nodejs templating engines Embedded JavaScript templates - EJS
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 library merged user-supplied options into the object used to render templates without restricting dangerous properties, so an attacker could set an option that was later evaluated as code.
What the attacker needed
Application passes user input as render options
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 lets a website build HTML pages by filling in blanks in a template. If a user can control some of the settings used while filling in those blanks, they may be able to sneak in instructions that the server runs as code, which is called server-side template injection. Here that could let an attacker run their own commands 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.