#BugBountyTip💰
A Node.js/Express application using the hbs view engine passed user-controlled request body directly as the options object to res.render, allowing an attacker to set a layout parameter that caused local file read. The file read could lead to remote code execution if the hbs version was old enough and a file upload feature existed.
Published on blog.shoebpatel.com
If you are using ExpressJs with Handlebars as templating engine invoked via hbs view engine, for Server Side Rendering, you are likely vulnerable to Local File Read (LFR) and potential Remote Code Execution (RCE).
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
The application passed the entire user-supplied profile object as the options argument to res.render, and the hbs template engine used the layout property from those options to construct a file path without validating it.
What the attacker needed
Express with hbs view engine; User input passed to res.render options; No validation of layout parameter
The fix
The code should be changed to pass the profile as a named property (res.render('index', { profile })) and prototype pollution should be fixed to prevent layout injection.
How it was found
- Send a POST request with a JSON body containing a profile object with a layout property pointing to a file path.
- The server responds with the contents of the requested file.
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.
When a web server builds a page, it often uses a template engine to fill in details. Here, the server took a value from the user and used it to decide which template file to load, without checking it. That let an attacker read files on the server, and possibly run their own code.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.