CVE-2019-20920: Handlebars Arbitrary Code Execution Vulnerability
HIGHCVE-2019-20920 is a HIGH (CVSS 8.1) arbitrary code execution vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Handlebars libraries in the npm ecosystem. The issue involves arbitrary code execution in handlebars. Remediation is available by upgrading affected packages to version 3.0.8, 4.5.3.
CVE-2019-20920 at a Glance
Security Impact
CVSS: 8.1
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:L/A:L).
How to Fix CVE-2019-20920
To remediate this vulnerability, upgrade all affected 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 handlebars@3.0.8
npm install handlebars@4.5.3
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
npm ls handlebars
How to Check if You Are Affected
To determine whether your Node.js application is affected by CVE-2019-20920, inspect your project dependencies using npm:
npm ls handlebars
Analyze the terminal output to locate any version of Handlebars in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.0.8), your application is affected.
Note: The npm ls 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 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-2019-20920 Affected Handlebars Versions
2 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
handlebars
|
npm |
< 3.0.8
|
3.0.8
|
|
handlebars
|
npm |
≥ 4.0.0
< 4.5.3
|
4.5.3
|
References
Frequently Asked Questions
What is CVE-2019-20920?
Which Handlebars versions are affected?
What version fixes CVE-2019-20920?
Is handlebars affected?
What is the CVSS score of CVE-2019-20920?
What CWE is associated with CVE-2019-20920?
How can I check npm dependencies for CVE-2019-20920?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-3cqr-58rm-57f8",
"modified" : "2021-04-22T23:38:32Z",
"published" : "2022-02-10T20:38:19Z",
"aliases" : [ "CVE-2019-20920" ],
"summary" : "Arbitrary Code Execution in Handlebars",
"details" : "Handlebars before 3.0.8 and 4.x before 4.5.3 is vulnerable to Arbitrary Code Execution. The lookup helper fails to properly validate templates, allowing attackers to submit templates that execute arbitrary JavaScript. This can be used to run arbitrary code on a server processing Handlebars templates or in a victim's browser (effectively serving as XSS).",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:L/A:L"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "npm",
"name" : "handlebars"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "3.0.8"
} ]
} ]
}, {
"package" : {
"ecosystem" : "npm",
"name" : "handlebars"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "4.0.0"
}, {
"fixed" : "4.5.3"
} ]
} ]
} ],
"references" : [ {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2019-20920"
}, {
"type" : "WEB",
"url" : "https://github.com/handlebars-lang/handlebars.js/commit/156061eb7707575293613d7fdf90e2bdaac029ee"
}, {
"type" : "WEB",
"url" : "https://github.com/handlebars-lang/handlebars.js/commit/d54137810a49939fd2ad01a91a34e182ece4528e"
}, {
"type" : "WEB",
"url" : "https://snyk.io/vuln/SNYK-JS-HANDLEBARS-534478"
}, {
"type" : "WEB",
"url" : "https://www.npmjs.com/advisories/1316"
}, {
"type" : "WEB",
"url" : "https://www.npmjs.com/advisories/1324"
}, {
"type" : "WEB",
"url" : "https://www.npmjs.com/package/handlebars"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-94" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2021-04-22T23:38:32Z",
"nvd_published_at" : "2020-09-30T18:15:00Z"
}
}