GitHub advisory · npm
node-tar: Global PAX extended header injects attacker-controlled linkpath into tar.Parser entries, bypassing strict-mode validation
Description
A tar archive with a Global Extended Header (PAX type g) with a linkpath field injects that value into every entry returned by tar.Parser , including plain File and Directory entries, with zero warnings under strict: true. This happens because header.js's #slurp() correctly excludes linkpath from global headers, but read-entry.js's #slurp() does not apply the same filter. Any application that consumes tar.Parser or tar.list() directly and uses entry.linkpath to build paths or create symlinks, without revalidating the value, can be made to read or write files outside the intended directory via a crafted symlink.
There are two separate #slurp() implementations apply Global Extended Header (g-type) fields to parsed state, and they filter different fields.
In src/header.js, #slurp(ex, gex = false) correctly excludes linkpath when gex is true:
// header.js (correct)
if (k === 'linkpath' && gex) continue;
In src/read-entry.js, the equivalent method has no such clause — it only excludes path:
// read-entry.js (bug: linkpath is not excluded)
if (k === 'path' && gex) continue;
// linkpath from the GEX is not filtered here
The execution flow:
parse.js calls Pax.parse(meta, gex, true) → stores the GEX object, including the linkpath fieldheader.js decode runs #slurp(gex, true) → correctly skips linkpath → header.linkpath is emptyconsumeHeader() checks header.linkpath (empty) → the "linkpath forbidden in global header" warning never firesReadEntry constructor runs this.#slurp(gex, true) → no linkpath filter → entry.linkpath is set to the attacker's value with no warning raisedConfirmed against tar@7.5.22:
node_modules/tar/dist/commonjs/read-entry.js lines 122–132 (buggy #slurp)node_modules/tar/dist/commonjs/header.js lines 184–194 (correct #slurp)Scope note: tar's own extraction engine…
Manual fix · npm
npm install tar@8.0.0Sources