GHSL-2021-018: File disclosure in Express Handlebars - CVE-2021-32820
Express Handlebars mixes template data with engine configuration options through the Express render API, allowing a user-controlled 'layout' parameter to specify an arbitrary file path. An attacker could exploit this to disclose files with existing extensions from the server.
Originally disclosed on GitHub Security Lab
The Express render API was designed to only pass in template data. By allowing template engine configuration options to be passed through the Express render API directly, downstream users of an Express template engine may inadvertently introduce insecure behavior into their applications with impacts ranging from Cross…
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 report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely, the template engine accepts configuration options (such as 'layout') through the same object used for template data, and downstream applications pass user-controlled input (e.g., req.query) directly to the render function.
Impact
An attacker could read files with existing extensions from the server, but files without an extension have '.handlebars' appended and cannot be read.
What the attacker needed
Application passes user-controlled object to render; Target file has an extension
The fix
The maintainers added documentation warning users about the potential danger of the pattern, but the proposed fix was ineffective.
How it was found
- Set up a vulnerable Express application that uses express-handlebars and passes req.query to res.render.
- Send a request with a 'layout' parameter pointing to a file with an extension, such as /tmp/test.file.
- The application renders the specified file as a layout, disclosing its contents.
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 report has not been written yet. The Original tab links to the source.
Express is a web framework for Node.js, and Handlebars is a template engine that fills in placeholders to create HTML. The problem is that Express Handlebars lets users set configuration options, like which layout file to use, through the same data they provide for the template. If an application passes user input directly, an attacker can change the layout to point to a file on the server, and its contents may be shown.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.