GitHub advisory · npm
node-tar: Symlink containment bypass via chained symlinks lets tar.x() create links that resolve outside the extraction directory (regression since 7.5.5)
Description
With default options, tar.x() in tar@7.5.22 (and every release since 7.5.5) extracts a symbolic link that resolves outside the extraction directory when the link target passes through another symlink from the same archive and then uses .. — for example sub/up -> .. followed by esc -> sub/up/... Both symlink-target checks collapse .. lexically before considering symlinks, so the intermediate symlink is never seen, while the kernel resolves it before applying ... With enough nesting the extracted link resolves to /.
This breaks the README guarantee that "Link and SymbolicLink entries are not allowed to target locations outside of the extraction folder", and gives any application that later reads or writes extracted paths file read/write outside the extraction root (the same impact model as GHSA-9ppj-qmqm-q256). It is a regression of the containment added for GHSA-8qq5-rm4j-mr97 (7.5.3–7.5.4 reject the chain; 7.5.5–7.5.22 accept it), and it also bypasses the [SYMLINK] check added for GHSA-83g3-92jg-28cx. A self-contained PoC, measured version matrix, and a remote-read deployment example are below.
Three entries, no file contents needed:
sub/ Directory
sub/up SymbolicLink -> .. lexical: "sub/.." = "." (inside)
esc SymbolicLink -> sub/up/.. lexical: "sub/up/.." = "sub" (inside)
On disk, the kernel resolves esc as sub/up → <cwd>, then .. → parent of <cwd>.
[STRIPABSOLUTEPATH]src/unpack.ts:284-291 at v7.5.22 (dist/commonjs/unpack.js:278-281):
// Resolve linkpath relative to the entry's directory.
// `path.posix` is safe to use because we're operating on
// tar paths, not a filesystem.
const entryDir = path.posix.dirname(entry.path)
const resolved = path.posix.normalize(
path.posix.join(entryDir, parts.join('/')),
)
// If the resolved path escapes (starts with ..), reject it
if…
Manual fix · npm
npm install tar@8.0.0Sources