# node-tar: Symlink linkpath containment bypass via entry paths ending in '/.'

node-tar validated symlink linkpaths against dirname(entry.path) but created links at resolve(cwd, entry.path); an entry named 'x/.' shifted the base and let '../outside/secret.txt' escape extraction.

- Payout: Research
- Severity: high
- Program: node-tar
- Found by: Figo5
- Disclosed: 2026-12-02
- CVE: CVE-2026-140245
- Write-up quality: 8/10
- Original: https://github.com/advisories/GHSA-jmj2-9c5q-vw73
- Library page: https://bugbountylibrary.com/r/ghsa%3AGHSA-jmj2-9c5q-vw73
- Tags: area:oss domain:oss impact:integrity kind:research platform:ghsa sev:high tech:nodejs technique:incomplete-fix technique:regression technique:source-review vuln:path-traversal

**Target:** npm tar package symlink extraction (src/unpack.ts)
**Root cause:** The linkpath containment check resolves relative linkpaths against path.posix.dirname(entry.path) while the link is actually created at path.resolve(cwd, entry.path); for entry names ending in '/.', dirname returns a base one level shallower, so one '..' is absorbed by the check but escapes at creation time.
**Steps:**
1. Craft archive entry `{ path: 'x/.', type: 'SymbolicLink', linkpath: '../outside/secret.txt' }`
2. Extract with default options (also works with `strip: 1`, PAX `path`, GNU `L`)
3. Check normalises `x/../outside/secret.txt` to `outside/secret.txt`, passing `startsWith('../')` at src/unpack.ts:291
4. Link is created at `path.resolve(cwd, 'x/.')` so kernel resolves `../outside/secret.txt` outside the destination
5. Control: entry `path: 'x'` (no '/.') is rejected with "linkpath escapes extraction directory"; 7.5.4 rejects with "linkpath contains '..'"
**How found:** Noticed the check base (path.posix.dirname(entry.path)) and the creation base (path.resolve(cwd, entry.path)) disagree; hypothesized that a trailing '/.' entry name makes dirname one level shallower so a single '..' survives the check, then verified against npm-published tar@7.5.22 with a property corpus of 1,464 pairs.
**Exploitation:** Consumer-mediated: node-tar itself cannot follow the link (mkdir refuses symlink parents, file writes use O_NOFOLLOW), but a caller that later writes through the extracted path writes outside the destination directory.
**Insight:** When a containment check and the actual filesystem operation compute their base path differently, look for entry names that make dirname/resolve disagree — trailing '/.', redundant separators, or dot segments — and diff the two computations rather than fuzzing payload strings.

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

**Malicious tar entry with 'x/.' symlink**

```
{ path: 'x/.', type: 'SymbolicLink', linkpath: '../outside/secret.txt' }
```

