Vulnerabilities in pkg:npm/express-handlebars

PACKAGE
Advisory Identifier: GHSA-fr76-2wp8-fp92
Advisory Summary

CVE-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.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:npm/express-handlebars

1 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:npm/express-handlebars. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-fr76-2wp8-fp92 CVE-2021-32820 HIGH Insecure template handling in Express-handlebars

CVE-2021-32820 at a Glance

CVE Identifier CVE-2021-32820
GHSA Identifier GHSA-fr76-2wp8-fp92
Severity HIGH
CVSS v3.1 Base Score 8.6
CWE Classification CWE-94: Improper Control of Generation of Code ('Code Injection')
Affected Product Express handlebars
Package Ecosystem npm
Published Date
Last Updated

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).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Changed (S:C)
Confidentiality High (C:H)
Integrity None (I:N)
Availability None (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.

express-handlebars fixed: 5.3.1
npm install express-handlebars@5.3.1
Verify Direct and Transitive Dependencies

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

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. A fix is discussed in https://github.com/express-handlebars/express-handlebars/pull/163

CVE-2021-32820 Affected Express handlebars Versions

1 component(s)
Fixed Versions:
5.3.1
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?
CVE-2021-32820 is a security vulnerability in Express handlebars involving Insecure template handling in Express-handlebars under CWE-94: Improper Control of Generation of Code ('Code Injection').
Which Express handlebars versions are affected?
Affected versions include releases prior to 5.3.1 across affected packages: express-handlebars.
What version fixes CVE-2021-32820?
Upgrading to 5.3.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is express-handlebars affected?
Yes, express-handlebars is affected in releases prior to 5.3.1. Upgrade your dependency to 5.3.1 or later.
What is the CVSS score of CVE-2021-32820?
CVE-2021-32820 has a CVSS v3.1 base score of 8.6 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:N/A:N.
What CWE is associated with CVE-2021-32820?
CVE-2021-32820 is classified under CWE-94: Improper Control of Generation of Code ('Code Injection') (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.).
How can I check npm dependencies for CVE-2021-32820?
Run the dependency tree command: 'npm ls express-handlebars'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "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"
  }
}