GHSL-2021-020: File disclosure in hbs - CVE-2021-32822
The hbs template engine mixes template data with engine configuration options when used with Express's render API, allowing an attacker to overwrite internal settings. This can lead to file disclosure in downstream applications that pass user-controlled objects directly to the render function.
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 hbs engine accepts configuration options through the same object used for template data, so user-controlled input can override internal settings.
Impact
An attacker could read arbitrary files from the server, but only if the downstream application passes user-controlled input directly to the render function.
What the attacker needed
Downstream app passes user input to render; hbs used as Express view engine
How it was found
- Set up an Express app with hbs as the view engine and pass req.query directly to res.render.
- Send a request with query parameters that set the views directory and layout option to a target file.
- The server responds with the contents of the target 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 report has not been written yet. The Original tab links to the source.
Template engines like hbs help build web pages by filling in data. Express, a web framework, lets you pass data to these engines. If the data comes from a user and includes special settings, an attacker might change how the engine works and read files on the server.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.