# GHSA-6WWR-G865-F46R: Nested symlink target can escape node-tar extraction root

- Database: GitHub
- Severity: medium (stated by ghsa, no CVSS score)
- Published: 2026-11-28
- Modified: 2026-12-01

## Tracked as

- [CVE-2026-140248](https://cve.now/CVE-2026-140248.md): node-tar file access outside extraction root via nested symlinks

## Affected versions

- tar (npm): from 7.5.22, fixed in 8.0.0

## Description

## Summary

With default `preservePaths: false`, `tar` 7.5.22 can extract a symbolic link whose effective target is outside the extraction directory. A crafted archive first creates one in-root symlink and then a second symlink whose target contains that symlink followed by `..`. The containment check simplifies the target lexically before checking filesystem symlinks, but the stored target is resolved by the OS through the first symlink. A later consumer following the extracted link can access a file outside the intended root.

I reproduced this locally on commit `2a22bfc5d3a432a606d9da0e2d87ba634aa3b1cb` (package version 7.5.22). Earlier versions were not assessed. The PoC only reads a marker that it creates in its own temporary directory. No preexisting file is touched.

## Root cause

`STRIPABSOLUTEPATH` accepts a symlink `linkpath` containing `..` if `path.posix.normalize(path.posix.join(entryDir, linkpath))` appears to stay inside the extraction root (`src/unpack.ts:263-302`). Later, `SYMLINK` derives `parts` using `path.resolve(dirname(entry.absolute), entry.linkpath)` (`src/unpack.ts:640-659`), which also removes `b/..` before `ENSURE_NO_SYMLINK` inspects each component (`src/unpack.ts:679-698`). `LINK` then writes the original unsimplified `entry.linkpath` with `fs.symlink` (`src/unpack.ts:866-880`).

For `a/b -> ../x` and `a/c -> b/../..`, the lexical check reduces the second target to the extraction root and never checks `a/b`. Actual filesystem traversal follows `a/b` to `x` first and then processes two parent components, ending in the extraction root's parent.

## Safe local PoC

Run from a built checkout of 7.5.22:

```js
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { Header, extract } from 'tar'

const parent = mkdtempSync(join(tmpdir(), 'node-tar-link-poc-'))
const out = join(parent, 'out')
mkdirSync(out)
writeFileSync(join(parent, 'outside-marker.txt'), 'OUTSIDE MARKER\n')
const block = h => {
  const b = Buffer.alloc(512)
  new Header(h).encode(b)
  return b
}
const input = join(parent, 'input.tar')
writeFileSync(input, Buffer.concat([
  block({ path: 'x/', type: 'Directory', size: 0 }),
  block({ path: 'a/', type: 'Directory', size: 0 }),
  block({ path: 'a/b', type: 'SymbolicLink', linkpath: '../x', size: 0 }),
  block({ path: 'a/c', type: 'SymbolicLink', linkpath: 'b/../..', size: 0 }),
  Buffer.alloc(1024),
]))

const warnings = []
await extract({ file: input, cwd: out, onwarn: (code, message) => warnings.push({ code, message }) })
console.log(readFileSync(join(out, 'a/c/outside-marker.txt'), 'utf8').trim())
console.log(warnings)
// OUTSIDE MARKER
// []
```

The marker is outside `out`; the access passes through a symlink extracted under `out`. This demonstrates the target containment bypass. It does not claim that node-tar itself writes outside `out` while extracting a subsequent member; its existing path checks may stop such an entry.

## Impact and suggested fix

An attacker needs to supply a tar archive to an application that extracts links and later follows or serves files from the extracted tree. The resulting link crosses the documented default target confinement. The downstream read/write impact depends on that consumer. I suggest medium severity.

Validate link targets using filesystem semantics before accepting them, or conservatively reject a target that traverses `..` after a symlink component. In particular, inspect the unsimplified components before `path.resolve()` removes them. Add a regression case with a symlink component followed by `..`, and assert that the second link is rejected under default options.

Please keep discussion and any fix private until release. I can validate a private patch and help with a regression test. Please credit GitHub user `@mikkel32` as finder/reporter in the published advisory; I will accept the pending credit invitation.

## References

- https://github.com/isaacs/node-tar/security/advisories/GHSA-6wwr-g865-f46r

Page: https://cve.now/GHSA-6WWR-G865-F46R

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
