# Permission model improperly protects against path traversal in Node.js 20

Node.js permission model's possiblyTransformPath called path.resolve dynamically, so app code overwriting path.resolve bypassed /../ resolution and read files outside allowed dirs.

- Payout: $2,330
- Severity: high
- Program: Internet Bug Bounty
- Found by: tniessen
- Disclosed: 2023-11-30
- CVE: CVE-2023-39331
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/2225660
- Library page: https://bugbountylibrary.com/r/h1%3A2225660
- Tags: area:oss domain:oss impact:data-leak impact:integrity kind:bounty platform:hackerone sev:high tech:nodejs technique:incomplete-fix technique:source-review vuln:access-control vuln:path-traversal

**Target:** Node.js experimental permission model (lib/internal/fs/utils.js possiblyTransformPath)
**Root cause:** possiblyTransformPath invoked pathModule.resolve as a dynamically looked-up property, so an application reassigning require('path').resolve to an identity function defeated path normalization and the fs permission check.
**Steps:**
1. Run Node 20 with `--experimental-permission --allow-fs-read=/tmp/`
2. In app code set `path.resolve = (s) => s`
3. Call `fs.readFileSync('/tmp/../etc/passwd')`
4. Observe /etc/passwd contents returned despite permission model restricting reads to /tmp/
**How found:** Researcher revisited the prior CVE-2023-30584 fix, read the patched possiblyTransformPath, and noticed it resolved the path via a mutable property lookup on the path module rather than a captured reference—hypothesizing monkey-patching would defeat it.
**Exploitation:** Any code running in the app context (e.g. dependency or injected script) reassigns path.resolve to a passthrough, then reads/writes arbitrary paths via /../ traversal, escaping the permission model's allowed roots.
**Insight:** When auditing a security fix, check whether the patched code calls security-critical built-ins via mutable property lookups (module.fn) instead of captured local references; monkey-patching those properties is a reliable bypass of permission/normalization checks.

## Proof of concept (copied exactly from the original report)

**Node command overriding path.resolve to read /etc/passwd**

```
$ node --experimental-permission --allow-fs-read=/tmp/ -p "path.resolve = (s) => s; fs.readFileSync('/tmp/../etc/passwd')"
<Buffer 72 6f 6f 74 3a 78 3a 30 3a 30 3a 72 6f 6f 74 3a 2f 72 6f 6f 74 3a 2f 62 69 6e 2f 62 61 73 68 0a 64 61 65 6d 6f 6e 3a 78 3a 31 3a 31 3a 64 61 65 6d 6f ... 3174 more bytes>
```

