# GHSA-442j-39wm-28r2: Handlebars.js has a Property Access Validation Bypass in container.lookup

- Severity: Low 3.7 (CVSS:3.1, scored by GitHub) `CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:N/A:N`
- Known to be exploited: not in CISA's catalogue, which lists only what CISA has confirmed
- Published: 2026-03-29T15:16:37.000Z
- Modified: 2026-09-10T03:50:36.874Z
- Weaknesses: CWE-367

## Description

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

(As written by GitHub Advisory Database.)

## Affected

- handlebars (npm): from 4.0.0 before 4.7.9

## References

- <https://github.com/handlebars-lang/handlebars.js/security/advisories/GHSA-442j-39wm-28r2> (web)
- <https://github.com/handlebars-lang/handlebars.js/commit/68d8df5a88e0a26fe9e6084c5c6aaebe67b07da2> (web)
- <https://github.com/handlebars-lang/handlebars.js> (package)
- <https://github.com/handlebars-lang/handlebars.js/releases/tag/v4.7.9> (web)

## Sources

- GitHub Advisory Database: [GHSA-442j-39wm-28r2](https://github.com/advisories/GHSA-442j-39wm-28r2), CC-BY-4.0, modified 2026-09-10

---

Page: https://cve.day/GHSA-442j-39wm-28r2 · Whole record: https://cve.day/GHSA-442j-39wm-28r2.json · Rebuilt by cve.day 2026-11-25T22:56:43.913Z
