GHSL-2021-025: Remote code execution and Reflected cross site scripting in haml-coffee - CVE-2021-32818
The haml-coffee template engine mixes template data with engine configuration options when used through the Express render API. An attacker could override configuration parameters such as customHtmlEscape or escapeHtml to achieve remote code execution or reflected cross-site scripting in downstream applications that pass user-controlled objects 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 template engine accepts configuration options through the same object used for template data, so user-controlled input can override security-relevant settings.
Impact
A remote attacker could execute arbitrary code on the server or perform reflected cross-site scripting against users of a downstream application that passes user-controlled objects to the haml-coffee render function.
What the attacker needed
Downstream app passes user-controlled object to render; haml-coffee used as Express view engine
The fix
The template engine should not accept configuration options through the Express render API; it should separate template data from engine configuration.
How it was found
- Set up an Express application using haml-coffee as the view engine and pass req.query directly to res.render.
- Send a request with a customHtmlEscape parameter containing code to execute.
- The code runs on the server, demonstrating remote code execution.
- Send a request with an escapeHtml parameter set to empty and a script tag in the name parameter.
- The script tag is reflected without sanitisation, demonstrating reflected XSS.
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 a web page. Express lets you pass data to the template, but haml-coffee also accepts settings in that same data. If a website passes user input directly, an attacker can change those settings to run code or inject scripts.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.