# node-tar: Symlink containment bypass via chained symlinks lets tar.x() create links that resolve outside the extraction directory (regression since 7.5.5)

node-tar 7.5.5–7.5.22 lexically normalizes symlink targets before checking, so a chained symlink through another archive symlink escapes the extraction dir up to /.

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

**Target:** npm tar library tar.x() archive extraction
**Root cause:** Both the [STRIPABSOLUTEPATH] lexical escape check and the [SYMLINK] ENSURE_NO_SYMLINK check call path.posix.normalize/path.resolve, collapsing '..' before the kernel resolves an intermediate symlink created by an earlier archive entry; the comment's assumption that tar paths are not filesystem paths fails once a real symlink exists on disk.
**Steps:**
1. Build archive with entries: `sub/` Directory, `sub/up` SymbolicLink -> `..`, `esc` SymbolicLink -> `sub/up/..`
2. Extract with `tar.x({ file, cwd })` defaults; both linkpaths normalize lexically inside cwd so no TAR_ENTRY_ERROR is raised
3. Observe `fs.realpathSync.native(OUT/esc)` resolves to parent of cwd (kernel resolves sub/up then applies ..)
4. For deeper escape, create N nested dirs, `d0/.../dN-1/up -> ../..(N times)`, `root -> d0/.../dN-1/up/..(N times)`; with N=12 root resolves to `/`
5. Read `OUT/root/etc/passwd` and sibling job files; write through `OUT/esc/config.json` to modify parent config
6. Deployment: serve extracted tree with `express.static`; GET `/sites/user-123/assets/etc/passwd` returns 200 with file contents
**How found:** Noticed the code comment claiming path.posix is safe because tar paths are not filesystem paths, then reasoned that an earlier archive entry can create a real symlink on disk, so lexical normalization of '..' diverges from kernel resolution; tested chained linkpaths against the version matrix and found 7.5.3–7.5.4 rejected but 7.5.5–7.5.22 accepted, indicating a regression from PR #450.
**Exploitation:** Attacker uploads a tarball containing a normal index.html plus a depth-12 symlink chain named `assets`. Server extracts with default tar.x() into a per-user dir and serves it via express.static; the symlink resolves to `/`, so HTTP GETs under `/assets/` read arbitrary files (e.g. /etc/passwd, other users' uploads) with the service's privileges. Writes through the link also modify files outside the extraction root.
**Escalation:** Nesting depth N controls how many levels above cwd the link climbs; N >= cwd depth reaches `/`, giving read/write to the whole filesystem accessible to the extracting process, including sibling tenants' directories.
**Insight:** When auditing archive extractors, check whether containment checks normalize paths lexically before the OS resolves symlinks created by earlier entries in the same archive; a linkpath like `a/b/..` where `a` is a symlink passes lexical checks but escapes at kernel resolution. Also verify the check's own realpath call uses native resolution, since Node's JS realpathSync normalizes '..' lexically and hides the escape.

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

**Malicious archive with chained symlink entries**

```
sub/        Directory
sub/up      SymbolicLink -> ..          lexical: "sub/.."    = "."    (inside)
esc         SymbolicLink -> sub/up/..   lexical: "sub/up/.." = "sub"  (inside)
```

