GitHub advisory · npm
node-tar: Symlink linkpath containment bypass via entry paths ending in '/.'
Description
A relative symlink linkpath is validated against path.posix.dirname(entry.path) but created at path.resolve(cwd, entry.path). An entry named 'x/.' shifts the check's base one level shallower, so one '..' is absorbed by the check and the link still escapes the extraction directory, with default options and no warning. Regression in 7.5.5-7.5.22 (introduced by the #450 fix).
[STRIPABSOLUTEPATH] resolves a relative linkpath against path.posix.dirname(entry.path) (src/unpack.ts:286), but the link is created at path.resolve(cwd, entry.path) (src/unpack.ts:359).
For an entry name ending in /., dirname returns a base one level shallower than the directory the link is actually created in. The check therefore normalises x/../outside/secret.txt to outside/secret.txt, which passes startsWith('../') at :291, while the kernel resolves the link from cwd and lands outside the destination.
>= 7.5.5, <= 7.5.22. The regression was introduced by e9a1ddb (the #450 relative-linkpath fix). 7.5.4 rejects the entry with linkpath contains '..'.
const base = path.posix.dirname(normalize(entry.path))
Using the same base the filesystem will use makes the check and the write agree. Verified against a 1,464-pair property corpus: 300 buggy pairs rejected, 0 legitimate pairs rejected, 0 new accepts; 677 existing tests pass.
Distinct from GHSA-9ppj-qmqm-q256: that finding is a malicious linkpath string (C:..); here the linkpath is ordinary and the defect is the entry-path base computation. #450 introduced this code, so it is the regression rather than a duplicate.
Reproduced against the npm-published tar@7.5.22 (not only a source checkout), with one archive entry and default options:
{ path: 'x/.', type: 'SymbolicLink', linkpath: '../outside/secret.txt' }
pad x -> ../outside/secret.txt realpath resolves outside dest…
Manual fix · npm
npm install tar@8.0.0Sources