GHSL-2021-019: File disclosure in express-hbs - CVE-2021-32817
The express-hbs template engine allowed configuration options such as the layout path to be passed through the Express render API alongside template data. An attacker could supply a layout parameter pointing to a file on the server, causing its contents to be disclosed.
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 engine did not separate template data from configuration options, so a user-controlled layout value was treated as a file path.
Impact
An attacker could read files on the server, but only files that already have an extension; files without an extension get .hbs appended.
What the attacker needed
Application passes req.query to res.render; target file has an extension
The fix
The maintainer added documentation warning users about the dangers of passing user-controlled objects into the render API.
How it was found
- The application passes the user-controlled query object directly into the render call.
- The attacker sends a request with a layout parameter pointing to a file on the server.
- The engine renders that file and returns 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.
Template engines fill in placeholders in web pages. Express lets you pass data to them, but express-hbs also accepted settings like which layout file to use from the same data. If a website passed user input straight into that data, an attacker could ask for a different file on the server and read it.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.