GHSA-442j-39wm-28r2: Handlebars Handlebars.js Has A Property Access Vulnerability

LOW
CVSS 3.7
CWE-367
Published
Advisory Summary

GHSA-442j-39wm-28r2 is a LOW (CVSS 3.7) handlebars.js has a property access vulnerability (CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition) affecting Handlebars libraries in the npm ecosystem. The issue involves handlebars.js has a property access validation bypass in container.lookup. Remediation is available by upgrading affected packages to version 4.7.9.

GHSA-442j-39wm-28r2 at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-442j-39wm-28r2
Severity LOW
CVSS v3.1 Base Score 3.7
CWE Classification CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition
Affected Product Handlebars
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 3.7

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:U/C:L/I:N/A:N).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality Low (C:L)
Integrity None (I:N)
Availability None (A:N)

How to Fix GHSA-442j-39wm-28r2

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.

handlebars fixed: 4.7.9
npm install handlebars@4.7.9
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 handlebars

How to Check if You Are Affected

To determine whether your Node.js application is affected by GHSA-442j-39wm-28r2, 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 4.7.9), 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-367: Time-of-check Time-of-use (TOCTOU) Race Condition, where the product checks the state of a resource before using that resource, but the resource's state can change between the check and the use in a way that invalidates the results of the check. 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

## Summary In `lib/handlebars/runtime.js`, the `container.lookup()` function uses `container.lookupProperty()` as a gate check to enforce prototype-access controls, but then discards the validated result and performs a second, unguarded property access (`depths[i][name]`). This Time-of-Check Time-of-Use (TOCTOU) pattern means the security check and the actual read are decoupled, and the raw access bypasses any sanitization that `lookupProperty` may perform. Only relevant when the **compat** compile option is enabled (`{compat: true}`), which activates `depthedLookup` in `lib/handlebars/compiler/javascript-compiler.js`. ## Description The vulnerable code in `lib/handlebars/runtime.js` (lines 137–144): ```javascript lookup: function (depths, name) { const len = depths.length; for (let i = 0; i < len; i++) { let result = depths[i] && container.lookupProperty(depths[i], name); if (result != null) { return depths[i][name]; // BUG: should be `return result;` } } }, ``` `container.lookupProperty()` (lines 119–136) enforces `hasOwnProperty` checks and `resultIsAllowed()` prototype-access controls. However, `container.lookup()` only uses `lookupProperty` as a boolean gate — if the gate passes (`result != null`), it then performs an independent, raw `depths[i][name]` access that circumvents any transformation or wrapped value that `lookupProperty` may have returned. ## Workarounds - Avoid enabling `{ compat: true }` when rendering templates that include untrusted data. - Ensure context data objects are plain JSON (no Proxies, no getter-based accessor properties).

GHSA-442j-39wm-28r2 Affected Handlebars Versions

1 component(s)
Fixed Versions:
4.7.9
Product / Package Ecosystem Affected Versions Fixed Version
handlebars
npm
≥ 4.0.0
< 4.7.9
4.7.9

References

Frequently Asked Questions

What is GHSA-442j-39wm-28r2?
GHSA-442j-39wm-28r2 is a security vulnerability in Handlebars involving Handlebars.js has a Property Access Validation Bypass in container.lookup under CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition.
Which Handlebars versions are affected?
Affected versions include releases prior to 4.7.9 across affected packages: handlebars.
What version fixes GHSA-442j-39wm-28r2?
Upgrading to 4.7.9 (or the latest patched release for your respective branch) resolves the vulnerability.
Is handlebars affected?
Yes, handlebars is affected in releases prior to 4.7.9. Upgrade your dependency to 4.7.9 or later.
What is the CVSS score of GHSA-442j-39wm-28r2?
GHSA-442j-39wm-28r2 has a CVSS v3.1 base score of 3.7 (LOW) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:N/A:N.
What CWE is associated with GHSA-442j-39wm-28r2?
GHSA-442j-39wm-28r2 is classified under CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition (The product checks the state of a resource before using that resource, but the resource's state can change between the check and the use in a way that invalidates the results of the check.).
How can I check npm dependencies for GHSA-442j-39wm-28r2?
Run the dependency tree command: 'npm ls 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-442j-39wm-28r2",
  "modified" : "2026-03-29T15:16:37Z",
  "published" : "2026-03-29T15:16:37Z",
  "aliases" : [ ],
  "summary" : "Handlebars.js has a Property Access Validation Bypass in container.lookup",
  "details" : "## Summary\n\nIn `lib/handlebars/runtime.js`, the `container.lookup()` function uses `container.lookupProperty()` as a gate check to enforce prototype-access controls, but then discards the validated result and performs a second, unguarded property access (`depths[i][name]`). This Time-of-Check Time-of-Use (TOCTOU) pattern means the security check and the actual read are decoupled, and the raw access bypasses any sanitization that `lookupProperty` may perform.\n\nOnly relevant when the **compat** compile option is enabled (`{compat: true}`), which activates `depthedLookup` in `lib/handlebars/compiler/javascript-compiler.js`.\n\n## Description\n\nThe vulnerable code in `lib/handlebars/runtime.js` (lines 137–144):\n\n```javascript\nlookup: function (depths, name) {\n  const len = depths.length;\n  for (let i = 0; i < len; i++) {\n    let result = depths[i] && container.lookupProperty(depths[i], name);\n    if (result != null) {\n      return depths[i][name];  // BUG: should be `return result;`\n    }\n  }\n},\n```\n\n`container.lookupProperty()` (lines 119–136) enforces `hasOwnProperty` checks and `resultIsAllowed()` prototype-access controls. However, `container.lookup()` only uses `lookupProperty` as a boolean gate — if the gate passes (`result != null`), it then performs an independent, raw `depths[i][name]` access that circumvents any transformation or wrapped value that `lookupProperty` may have returned.\n\n## Workarounds\n\n- Avoid enabling `{ compat: true }` when rendering templates that include untrusted data.\n- Ensure context data objects are plain JSON (no Proxies, no getter-based accessor properties).",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:N/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "handlebars"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "4.0.0"
      }, {
        "fixed" : "4.7.9"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 4.7.8"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/handlebars-lang/handlebars.js/security/advisories/GHSA-442j-39wm-28r2"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/handlebars-lang/handlebars.js/commit/68d8df5a88e0a26fe9e6084c5c6aaebe67b07da2"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/handlebars-lang/handlebars.js"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/handlebars-lang/handlebars.js/releases/tag/v4.7.9"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-367" ],
    "severity" : "LOW",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-03-29T15:16:37Z",
    "nvd_published_at" : null
  }
}