# fs.fchown/fchmod bypasses permission model

Node.js experimental permission model checked paths not file descriptors, so fs.fchown/fs.fchmod on a read-only fd bypassed --allow-fs-write to change file ownership and permissions.

- Payout: $249
- Severity: low
- Program: Internet Bug Bounty
- Found by: 4xpl0r3r
- Disclosed: 2024-10-16
- CVE: CVE-2024-36137
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/2590608
- Library page: https://bugbountylibrary.com/r/h1%3A2590608
- Tags: area:oss domain:oss impact:integrity kind:bounty platform:hackerone sev:low tech:nodejs technique:source-review vuln:access-control

**Target:** Node.js permission model (fs.fchown/fs.fchmod file descriptor operations)
**Root cause:** The permission model enforces restrictions on file paths but not on file descriptors, so fd-based operations like fs.fchown and fs.fchmod can mutate a file opened read-only without triggering the --allow-fs-write check.
**Steps:**
1. Enable experimental permission model with `--experimental-permission --allow-fs-read=/path` (no --allow-fs-write).
2. Open a target file read-only to obtain an fd: `fs.openSync('/path/file','r')`.
3. Call `fs.fchmodSync(fd, 0o777)` or `fs.fchownSync(fd, uid, gid)` on the read-only fd.
4. Observe the file's permissions/owner change despite write being disallowed.
**How found:** Researcher noticed the permission model operates on paths, not file descriptors, and reasoned that fd-based fs operations (fchown/fchmod) would not be gated by --allow-fs-write.
**Exploitation:** An attacker with code execution under the permission model (e.g. untrusted code run with --allow-fs-read only) opens a file read-only and uses fs.fchmod/fs.fchown on the descriptor to alter permissions or ownership, escaping the intended write restriction.
**Insight:** When a sandbox/permission layer gates by path string, audit every API that accepts a file descriptor or handle instead of a path—fd-based variants (fchmod, fchown, futimes) often skip the check.

