Arbitrary File Creation/Overwrite on Windows via insufficient relative path sanitization
Description
The npm package "tar" (aka node-tar) before versions 4.4.18, 5.0.10, and 6.1.9 has an arbitrary file creation/overwrite and arbitrary code execution vulnerability. node-tar aims to guarantee that any file whose location would be outside of the extraction target directory is not extracted. This is, in part, accomplished by sanitizing absolute paths of entries within the archive, skipping archive entries that contain .. path portions, and resolving the sanitized paths against the extraction target directory. This logic was insufficient on Windows systems when extracting tar files that contained a path that was not an absolute path, but specified a drive letter different from the extraction target, such as C:some\path. If the drive letter does not match the extraction target, for example D:\extraction\dir, then the result of path.resolve(extractionDirectory, entryPath) would resolve against the current working directory on the C: drive, rather than the extraction target directory. Additionally, a .. portion of the path could occur immediately after the drive letter, such as C:../foo, and was not properly sanitized by the logic that checked for .. within the normalized and split portions of the path. This only affects users of node-tar on Windows systems. These issues were addressed in releases 4.4.18, 5.0.10 and 6.1.9. The v3 branch of node-tar has been deprecated and did not receive patches for these issues. If you are still using a v3 release we recommend you update to a more recent version of node-tar. There is no reasonable way to work around this issue without performing the same path normalization procedures that node-tar now does. Users are encouraged to upgrade to the latest patched versions of node-tar, rather than attempt to sanitize paths themselves.
AI Insight
LLM-synthesized narrative grounded in this CVE's description and references.
Node-tar on Windows allows arbitrary file creation/overwrite via insufficient sanitization of drive-relative paths, leading to potential code execution.
Vulnerability
The node-tar package (versions before 4.4.18, 5.0.10, and 6.1.9) contains a path traversal vulnerability on Windows systems. When extracting a tar archive, the library attempts to prevent files from being written outside the extraction target directory by sanitizing absolute paths and skipping entries with .. segments. However, on Windows, a path like C:some\path (a drive-relative path without a backslash after the drive letter) is not treated as absolute. The path.resolve(extractionDirectory, entryPath) call resolves such a path against the current working directory on the specified drive, which may differ from the extraction target drive. Additionally, a path like C:../foo bypasses the .. check because the .. appears immediately after the drive letter. This allows an attacker to write files to arbitrary locations on the system. [2][3]
Exploitation
An attacker must craft a tar archive containing entries with specially crafted paths that use a drive letter different from the extraction target, e.g., C:..\malicious.exe when extracting to D:\target. The attacker does not need authentication if the victim extracts the archive using a vulnerable version of node-tar on Windows. The victim must extract the archive (e.g., via npm install or manual extraction). No special privileges are required beyond the ability to create a tar file. [2][3]
Impact
Successful exploitation allows an attacker to create or overwrite arbitrary files on the Windows filesystem. This can lead to arbitrary code execution if the overwritten file is executable or if a configuration file is modified. The attacker can achieve file write outside the intended extraction directory, potentially gaining control over the system or user environment. [2][3]
Mitigation
The vulnerability is fixed in node-tar versions 4.4.18, 5.0.10, and 6.1.9. Users should upgrade to these versions immediately. The deprecated v3 branch did not receive a patch. There is no reasonable workaround; users must upgrade. The fix strips path roots from all paths before resolution and properly checks for .. after drive letters. [2][3][4]
AI Insight generated on May 21, 2026. Synthesized from this CVE's description and the cited reference URLs; citations are validated against the source bundle.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
tarnpm | < 4.4.18 | 4.4.18 |
tarnpm | >= 5.0.0, < 5.0.10 | 5.0.10 |
tarnpm | >= 6.0.0, < 6.1.9 | 6.1.9 |
Affected products
9- osv-coords8 versionspkg:deb/ubuntu/node-tarpkg:npm/tarpkg:rpm/suse/nodejs12&distro=SUSE%20Linux%20Enterprise%20Module%20for%20Web%20and%20Scripting%2012pkg:rpm/suse/nodejs12&distro=SUSE%20Linux%20Enterprise%20Module%20for%20Web%20and%20Scripting%2015%20SP2pkg:rpm/suse/nodejs12&distro=SUSE%20Linux%20Enterprise%20Module%20for%20Web%20and%20Scripting%2015%20SP3pkg:rpm/suse/nodejs14&distro=SUSE%20Linux%20Enterprise%20Module%20for%20Web%20and%20Scripting%2012pkg:rpm/suse/nodejs14&distro=SUSE%20Linux%20Enterprise%20Module%20for%20Web%20and%20Scripting%2015%20SP2pkg:rpm/suse/nodejs14&distro=SUSE%20Linux%20Enterprise%20Module%20for%20Web%20and%20Scripting%2015%20SP3
>= 0+ 7 more
- (no CPE)range: >= 0
- (no CPE)range: < 4.4.18
- (no CPE)range: < 12.22.9-1.38.1
- (no CPE)range: < 12.22.7-4.22.1
- (no CPE)range: < 12.22.7-4.22.1
- (no CPE)range: < 14.18.1-6.18.2
- (no CPE)range: < 14.18.1-15.21.2
- (no CPE)range: < 14.18.1-15.21.2
- npm/node-tarv5Range: < 4.4.18
Patches
352b09e309bcafix: prevent path escape using drive-relative paths
3 files changed · +79 −15
lib/strip-absolute-path.js+12 −2 modified@@ -2,13 +2,23 @@ const { isAbsolute, parse } = require('path').win32 // returns [root, stripped] +// Note that windows will think that //x/y/z/a has a "root" of //x/y, and in +// those cases, we want to sanitize it to x/y/z/a, not z/a, so we strip / +// explicitly if it's the first character. +// drive-specific relative paths on Windows get their root stripped off even +// though they are not absolute, so `c:../foo` becomes ['c:', '../foo'] module.exports = path => { let r = '' - while (isAbsolute(path)) { + + let parsed = parse(path) + while (isAbsolute(path) || parsed.root) { // windows will think that //x/y/z has a "root" of //x/y/ - const root = path.charAt(0) === '/' ? '/' : parse(path).root + // but strip the //?/C:/ off of //?/C:/path + const root = path.charAt(0) === '/' && path.slice(0, 4) !== '//?/' ? '/' + : parsed.root path = path.substr(root.length) r += root + parsed = parse(path) } return [r, path] }
lib/unpack.js+19 −3 modified@@ -236,13 +236,13 @@ class Unpack extends Parser { if (!this.preservePaths) { const p = normPath(entry.path) - if (p.split('/').includes('..')) { + const parts = p.split('/') + if (parts.includes('..') || isWindows && /^[a-z]:\.\.$/i.test(parts[0])) { this.warn(`path contains '..'`, p) return false } - // absolutes on posix are also absolutes on win32 - // so we only need to test this one to get both + // strip off the root const s = stripAbsolutePath(p) if (s[0]) { entry.path = s[1] @@ -255,6 +255,22 @@ class Unpack extends Parser { else entry.absolute = normPath(path.resolve(this.cwd, entry.path)) + // if we somehow ended up with a path that escapes the cwd, and we are + // not in preservePaths mode, then something is fishy! This should have + // been prevented above, so ignore this for coverage. + /* istanbul ignore if - defense in depth */ + if (!this.preservePaths && + entry.absolute.indexOf(this.cwd + '/') !== 0 && + entry.absolute !== this.cwd) { + this.warn('TAR_ENTRY_ERROR', 'path escaped extraction target', { + entry, + path: normPath(entry.path), + resolvedPath: entry.absolute, + cwd: this.cwd, + }) + return false + } + // an archive can set properties on the extraction directory, but it // may not replace the cwd with a different kind of thing entirely. if (entry.absolute === this.cwd &&
test/strip-absolute-path.js+48 −10 modified@@ -1,14 +1,52 @@ const t = require('tap') const stripAbsolutePath = require('../lib/strip-absolute-path.js') +const cwd = process.cwd() +const requireInject = require('require-inject') -const cases = { - '/': ['/', ''], - '////': ['////', ''], - 'c:///a/b/c': ['c:///', 'a/b/c'], - '\\\\foo\\bar\\baz': ['\\\\foo\\bar\\', 'baz'], - '//foo//bar//baz': ['//', 'foo//bar//baz'], - 'c:\\c:\\c:\\c:\\\\d:\\e/f/g': ['c:\\c:\\c:\\c:\\\\d:\\', 'e/f/g'], -} +t.test('basic', t => { + const cases = { + '/': ['/', ''], + '////': ['////', ''], + 'c:///a/b/c': ['c:///', 'a/b/c'], + '\\\\foo\\bar\\baz': ['\\\\foo\\bar\\', 'baz'], + '//foo//bar//baz': ['//', 'foo//bar//baz'], + 'c:\\c:\\c:\\c:\\\\d:\\e/f/g': ['c:\\c:\\c:\\c:\\\\d:\\', 'e/f/g'], + } -for (const [input, [root, stripped]] of Object.entries(cases)) - t.strictSame(stripAbsolutePath(input), [root, stripped], input) + for (const [input, [root, stripped]] of Object.entries(cases)) + t.strictSame(stripAbsolutePath(input, cwd), [root, stripped], input) + t.end() +}) + +t.test('drive-local paths', t => { + const env = process.env + t.teardown(() => process.env = env) + const cwd = 'D:\\safety\\land' + const realPath = require('path') + // be windowsy + const path = { + ...realPath.win32, + win32: realPath.win32, + posix: realPath.posix, + } + const stripAbsolutePath = requireInject('../lib/strip-absolute-path.js', { path }) + const cases = { + '/': ['/', ''], + '////': ['////', ''], + 'c:///a/b/c': ['c:///', 'a/b/c'], + '\\\\foo\\bar\\baz': ['\\\\foo\\bar\\', 'baz'], + '//foo//bar//baz': ['//', 'foo//bar//baz'], + 'c:\\c:\\c:\\c:\\\\d:\\e/f/g': ['c:\\c:\\c:\\c:\\\\d:\\', 'e/f/g'], + 'c:..\\system\\explorer.exe': ['c:', '..\\system\\explorer.exe'], + 'd:..\\..\\unsafe\\land': ['d:', '..\\..\\unsafe\\land'], + 'c:foo': ['c:', 'foo'], + 'D:mark': ['D:', 'mark'], + '//?/X:/y/z': ['//?/X:/', 'y/z'], + '\\\\?\\X:\\y\\z': ['\\\\?\\X:\\', 'y\\z'], + } + for (const [input, [root, stripped]] of Object.entries(cases)) { + if (!t.strictSame(stripAbsolutePath(input, cwd), [root, stripped], input)) + break + } + t.end() +})
82eac952f7c1fix: prevent path escape using drive-relative paths
3 files changed · +79 −15
lib/strip-absolute-path.js+12 −2 modified@@ -2,13 +2,23 @@ const { isAbsolute, parse } = require('path').win32 // returns [root, stripped] +// Note that windows will think that //x/y/z/a has a "root" of //x/y, and in +// those cases, we want to sanitize it to x/y/z/a, not z/a, so we strip / +// explicitly if it's the first character. +// drive-specific relative paths on Windows get their root stripped off even +// though they are not absolute, so `c:../foo` becomes ['c:', '../foo'] module.exports = path => { let r = '' - while (isAbsolute(path)) { + + let parsed = parse(path) + while (isAbsolute(path) || parsed.root) { // windows will think that //x/y/z has a "root" of //x/y/ - const root = path.charAt(0) === '/' ? '/' : parse(path).root + // but strip the //?/C:/ off of //?/C:/path + const root = path.charAt(0) === '/' && path.slice(0, 4) !== '//?/' ? '/' + : parsed.root path = path.substr(root.length) r += root + parsed = parse(path) } return [r, path] }
lib/unpack.js+19 −3 modified@@ -246,16 +246,16 @@ class Unpack extends Parser { if (!this.preservePaths) { const p = normPath(entry.path) - if (p.split('/').includes('..')) { + const parts = p.split('/') + if (parts.includes('..') || isWindows && /^[a-z]:\.\.$/i.test(parts[0])) { this.warn('TAR_ENTRY_ERROR', `path contains '..'`, { entry, path: p, }) return false } - // absolutes on posix are also absolutes on win32 - // so we only need to test this one to get both + // strip off the root const [root, stripped] = stripAbsolutePath(p) if (root) { entry.path = stripped @@ -271,6 +271,22 @@ class Unpack extends Parser { else entry.absolute = normPath(path.resolve(this.cwd, entry.path)) + // if we somehow ended up with a path that escapes the cwd, and we are + // not in preservePaths mode, then something is fishy! This should have + // been prevented above, so ignore this for coverage. + /* istanbul ignore if - defense in depth */ + if (!this.preservePaths && + entry.absolute.indexOf(this.cwd + '/') !== 0 && + entry.absolute !== this.cwd) { + this.warn('TAR_ENTRY_ERROR', 'path escaped extraction target', { + entry, + path: normPath(entry.path), + resolvedPath: entry.absolute, + cwd: this.cwd, + }) + return false + } + // an archive can set properties on the extraction directory, but it // may not replace the cwd with a different kind of thing entirely. if (entry.absolute === this.cwd &&
test/strip-absolute-path.js+48 −10 modified@@ -1,14 +1,52 @@ const t = require('tap') const stripAbsolutePath = require('../lib/strip-absolute-path.js') +const cwd = process.cwd() +const requireInject = require('require-inject') -const cases = { - '/': ['/', ''], - '////': ['////', ''], - 'c:///a/b/c': ['c:///', 'a/b/c'], - '\\\\foo\\bar\\baz': ['\\\\foo\\bar\\', 'baz'], - '//foo//bar//baz': ['//', 'foo//bar//baz'], - 'c:\\c:\\c:\\c:\\\\d:\\e/f/g': ['c:\\c:\\c:\\c:\\\\d:\\', 'e/f/g'], -} +t.test('basic', t => { + const cases = { + '/': ['/', ''], + '////': ['////', ''], + 'c:///a/b/c': ['c:///', 'a/b/c'], + '\\\\foo\\bar\\baz': ['\\\\foo\\bar\\', 'baz'], + '//foo//bar//baz': ['//', 'foo//bar//baz'], + 'c:\\c:\\c:\\c:\\\\d:\\e/f/g': ['c:\\c:\\c:\\c:\\\\d:\\', 'e/f/g'], + } -for (const [input, [root, stripped]] of Object.entries(cases)) - t.strictSame(stripAbsolutePath(input), [root, stripped], input) + for (const [input, [root, stripped]] of Object.entries(cases)) + t.strictSame(stripAbsolutePath(input, cwd), [root, stripped], input) + t.end() +}) + +t.test('drive-local paths', t => { + const env = process.env + t.teardown(() => process.env = env) + const cwd = 'D:\\safety\\land' + const realPath = require('path') + // be windowsy + const path = { + ...realPath.win32, + win32: realPath.win32, + posix: realPath.posix, + } + const stripAbsolutePath = requireInject('../lib/strip-absolute-path.js', { path }) + const cases = { + '/': ['/', ''], + '////': ['////', ''], + 'c:///a/b/c': ['c:///', 'a/b/c'], + '\\\\foo\\bar\\baz': ['\\\\foo\\bar\\', 'baz'], + '//foo//bar//baz': ['//', 'foo//bar//baz'], + 'c:\\c:\\c:\\c:\\\\d:\\e/f/g': ['c:\\c:\\c:\\c:\\\\d:\\', 'e/f/g'], + 'c:..\\system\\explorer.exe': ['c:', '..\\system\\explorer.exe'], + 'd:..\\..\\unsafe\\land': ['d:', '..\\..\\unsafe\\land'], + 'c:foo': ['c:', 'foo'], + 'D:mark': ['D:', 'mark'], + '//?/X:/y/z': ['//?/X:/', 'y/z'], + '\\\\?\\X:\\y\\z': ['\\\\?\\X:\\', 'y\\z'], + } + for (const [input, [root, stripped]] of Object.entries(cases)) { + if (!t.strictSame(stripAbsolutePath(input, cwd), [root, stripped], input)) + break + } + t.end() +})
875a37e3ec03fix: prevent path escape using drive-relative paths
4 files changed · +161 −15
lib/strip-absolute-path.js+12 −2 modified@@ -2,13 +2,23 @@ const { isAbsolute, parse } = require('path').win32 // returns [root, stripped] +// Note that windows will think that //x/y/z/a has a "root" of //x/y, and in +// those cases, we want to sanitize it to x/y/z/a, not z/a, so we strip / +// explicitly if it's the first character. +// drive-specific relative paths on Windows get their root stripped off even +// though they are not absolute, so `c:../foo` becomes ['c:', '../foo'] module.exports = path => { let r = '' - while (isAbsolute(path)) { + + let parsed = parse(path) + while (isAbsolute(path) || parsed.root) { // windows will think that //x/y/z has a "root" of //x/y/ - const root = path.charAt(0) === '/' ? '/' : parse(path).root + // but strip the //?/C:/ off of //?/C:/path + const root = path.charAt(0) === '/' && path.slice(0, 4) !== '//?/' ? '/' + : parsed.root path = path.substr(root.length) r += root + parsed = parse(path) } return [r, path] }
lib/unpack.js+19 −3 modified@@ -247,16 +247,16 @@ class Unpack extends Parser { if (!this.preservePaths) { const p = normPath(entry.path) - if (p.split('/').includes('..')) { + const parts = p.split('/') + if (parts.includes('..') || isWindows && /^[a-z]:\.\.$/i.test(parts[0])) { this.warn('TAR_ENTRY_ERROR', `path contains '..'`, { entry, path: p, }) return false } - // absolutes on posix are also absolutes on win32 - // so we only need to test this one to get both + // strip off the root const [root, stripped] = stripAbsolutePath(p) if (root) { entry.path = stripped @@ -272,6 +272,22 @@ class Unpack extends Parser { else entry.absolute = normPath(path.resolve(this.cwd, entry.path)) + // if we somehow ended up with a path that escapes the cwd, and we are + // not in preservePaths mode, then something is fishy! This should have + // been prevented above, so ignore this for coverage. + /* istanbul ignore if - defense in depth */ + if (!this.preservePaths && + entry.absolute.indexOf(this.cwd + '/') !== 0 && + entry.absolute !== this.cwd) { + this.warn('TAR_ENTRY_ERROR', 'path escaped extraction target', { + entry, + path: normPath(entry.path), + resolvedPath: entry.absolute, + cwd: this.cwd, + }) + return false + } + // an archive can set properties on the extraction directory, but it // may not replace the cwd with a different kind of thing entirely. if (entry.absolute === this.cwd &&
test/strip-absolute-path.js+47 −10 modified@@ -1,14 +1,51 @@ const t = require('tap') const stripAbsolutePath = require('../lib/strip-absolute-path.js') +const cwd = process.cwd() -const cases = { - '/': ['/', ''], - '////': ['////', ''], - 'c:///a/b/c': ['c:///', 'a/b/c'], - '\\\\foo\\bar\\baz': ['\\\\foo\\bar\\', 'baz'], - '//foo//bar//baz': ['//', 'foo//bar//baz'], - 'c:\\c:\\c:\\c:\\\\d:\\e/f/g': ['c:\\c:\\c:\\c:\\\\d:\\', 'e/f/g'], -} +t.test('basic', t => { + const cases = { + '/': ['/', ''], + '////': ['////', ''], + 'c:///a/b/c': ['c:///', 'a/b/c'], + '\\\\foo\\bar\\baz': ['\\\\foo\\bar\\', 'baz'], + '//foo//bar//baz': ['//', 'foo//bar//baz'], + 'c:\\c:\\c:\\c:\\\\d:\\e/f/g': ['c:\\c:\\c:\\c:\\\\d:\\', 'e/f/g'], + } -for (const [input, [root, stripped]] of Object.entries(cases)) - t.strictSame(stripAbsolutePath(input), [root, stripped], input) + for (const [input, [root, stripped]] of Object.entries(cases)) + t.strictSame(stripAbsolutePath(input, cwd), [root, stripped], input) + t.end() +}) + +t.test('drive-local paths', t => { + const env = process.env + t.teardown(() => process.env = env) + const cwd = 'D:\\safety\\land' + const realPath = require('path') + // be windowsy + const path = { + ...realPath.win32, + win32: realPath.win32, + posix: realPath.posix, + } + const stripAbsolutePath = t.mock('../lib/strip-absolute-path.js', { path }) + const cases = { + '/': ['/', ''], + '////': ['////', ''], + 'c:///a/b/c': ['c:///', 'a/b/c'], + '\\\\foo\\bar\\baz': ['\\\\foo\\bar\\', 'baz'], + '//foo//bar//baz': ['//', 'foo//bar//baz'], + 'c:\\c:\\c:\\c:\\\\d:\\e/f/g': ['c:\\c:\\c:\\c:\\\\d:\\', 'e/f/g'], + 'c:..\\system\\explorer.exe': ['c:', '..\\system\\explorer.exe'], + 'd:..\\..\\unsafe\\land': ['d:', '..\\..\\unsafe\\land'], + 'c:foo': ['c:', 'foo'], + 'D:mark': ['D:', 'mark'], + '//?/X:/y/z': ['//?/X:/', 'y/z'], + '\\\\?\\X:\\y\\z': ['\\\\?\\X:\\', 'y\\z'], + } + for (const [input, [root, stripped]] of Object.entries(cases)) { + if (!t.strictSame(stripAbsolutePath(input, cwd), [root, stripped], input)) + break + } + t.end() +})
test/unpack.js+83 −0 modified@@ -3144,3 +3144,86 @@ t.test('dircache prune all on windows when symlink encountered', t => { t.end() }) + +t.test('recognize C:.. as a dot path part', t => { + if (process.platform !== 'win32') { + process.env.TESTING_TAR_FAKE_PLATFORM = 'win32' + t.teardown(() => { + delete process.env.TESTING_TAR_FAKE_PLATFORM + }) + } + const Unpack = t.mock('../lib/unpack.js', { + path: { + ...path.win32, + win32: path.win32, + posix: path.posix, + }, + }) + const UnpackSync = Unpack.Sync + + const data = makeTar([ + { + type: 'File', + path: 'C:../x/y/z', + size: 1, + }, + 'z', + { + type: 'File', + path: 'x:..\\y\\z', + size: 1, + }, + 'x', + { + type: 'File', + path: 'Y:foo', + size: 1, + }, + 'y', + '', + '', + ]) + + const check = (path, warnings, t) => { + t.equal(fs.readFileSync(`${path}/foo`, 'utf8'), 'y') + t.strictSame(warnings, [ + [ + 'TAR_ENTRY_ERROR', + "path contains '..'", + 'C:../x/y/z', + 'C:../x/y/z', + ], + ['TAR_ENTRY_ERROR', "path contains '..'", 'x:../y/z', 'x:../y/z'], + [ + 'TAR_ENTRY_INFO', + 'stripping Y: from absolute path', + 'Y:foo', + 'foo', + ], + ]) + t.end() + } + + t.test('async', t => { + const warnings = [] + const path = t.testdir() + new Unpack({ + cwd: path, + onwarn: (c, w, { entry, path }) => warnings.push([c, w, path, entry.path]), + }) + .on('close', () => check(path, warnings, t)) + .end(data) + }) + + t.test('sync', t => { + const warnings = [] + const path = t.testdir() + new UnpackSync({ + cwd: path, + onwarn: (c, w, { entry, path }) => warnings.push([c, w, path, entry.path]), + }).end(data) + check(path, warnings, t) + }) + + t.end() +})
Vulnerability mechanics
Generated on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
9- github.com/advisories/GHSA-5955-9wpr-37jhghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2021-37713ghsaADVISORY
- cert-portal.siemens.com/productcert/pdf/ssa-389290.pdfghsax_refsource_CONFIRMWEB
- github.com/isaacs/node-tar/commit/52b09e309bcae0c741a7eb79a17ef36e7828b946ghsaWEB
- github.com/isaacs/node-tar/commit/82eac952f7c10765969ed464e549375854b26edcghsaWEB
- github.com/isaacs/node-tar/commit/875a37e3ec031186fc6599f6807341f56c584598ghsaWEB
- github.com/npm/node-tar/security/advisories/GHSA-5955-9wpr-37jhghsax_refsource_CONFIRMWEB
- www.npmjs.com/package/targhsax_refsource_MISCWEB
- www.oracle.com/security-alerts/cpuoct2021.htmlghsax_refsource_MISCWEB
News mentions
0No linked articles in our index yet.