CVE-2021-32820: Express handlebars Insecure Template Handling Vulnerability
HIGHCVE-2021-32820 is a HIGH (CVSS 8.6) insecure template handling vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Express handlebars libraries in the npm ecosystem. The issue involves insecure template handling in express-handlebars. Remediation is available by upgrading affected packages to version 5.3.1.
CVE-2021-32820 at a Glance
Security Impact
CVSS: 8.6
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:N/A:N).
How to Fix CVE-2021-32820
To remediate this vulnerability, upgrade all affected Express handlebars dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
npm install express-handlebars@5.3.1
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
npm ls express-handlebars
How to Check if You Are Affected
To determine whether your Node.js application is affected by CVE-2021-32820, inspect your project dependencies using npm:
npm ls express-handlebars
Analyze the terminal output to locate any version of Express handlebars in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 5.3.1), your application is affected.
Note: The npm ls express-handlebars command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-94: Improper Control of Generation of Code ('Code Injection'), where the product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. In Express handlebars, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2021-32820 Affected Express handlebars Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
express-handlebars
|
npm |
< 5.3.1
|
5.3.1
|
References
Frequently Asked Questions
What is CVE-2021-32820?
Which Express handlebars versions are affected?
What version fixes CVE-2021-32820?
Is express-handlebars affected?
What is the CVSS score of CVE-2021-32820?
What CWE is associated with CVE-2021-32820?
How can I check npm dependencies for CVE-2021-32820?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-fr76-2wp8-fp92",
"modified" : "2023-09-05T23:08:50Z",
"published" : "2022-02-10T23:35:21Z",
"aliases" : [ "CVE-2021-32820" ],
"summary" : "Insecure template handling in Express-handlebars",
"details" : "Express-handlebars is a Handlebars view engine for Express. Express-handlebars mixes pure template data with engine configuration options through the Express render API. More specifically, the layout parameter may trigger file disclosure vulnerabilities in downstream applications. This potential vulnerability is somewhat restricted in that only files with existing extentions (i.e. file.extension) can be included, files that lack an extension will have `.handlebars` appended to them. For complete details refer to the referenced GHSL-2021-018 report. Notes in documentation have been added to help users avoid this potential information exposure vulnerability.\n\nA fix is discussed in https://github.com/express-handlebars/express-handlebars/pull/163",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:N/A:N"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "npm",
"name" : "express-handlebars"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "5.3.1"
} ]
} ]
} ],
"references" : [ {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-32820"
}, {
"type" : "WEB",
"url" : "https://github.com/express-handlebars/express-handlebars/pull/163"
}, {
"type" : "WEB",
"url" : "https://github.com/express-handlebars/express-handlebars/commit/78c47a235c4ad7bc2674bddd8ec2721567ed8c72"
}, {
"type" : "WEB",
"url" : "https://github.com/express-handlebars/express-handlebars#danger-"
}, {
"type" : "WEB",
"url" : "https://github.com/express-handlebars/express-handlebars/blob/78c47a235c4ad7bc2674bddd8ec2721567ed8c72/README.md#danger-"
}, {
"type" : "ADVISORY",
"url" : "https://securitylab.github.com/advisories/GHSL-2021-018-express-handlebars"
}, {
"type" : "WEB",
"url" : "https://www.npmjs.com/package/express-handlebars"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-200", "CWE-94" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2021-05-17T18:45:00Z",
"nvd_published_at" : "2021-05-14T19:15:00Z"
}
}