Skip to main content
Menu
Advisories

Uncaught Exception DoS in tar Extraction via NUL Bytes Surviving Line-Terminator-Blind String Sanitization

GHSA-XV7H-RGQ8-7M7VPublished Updated GitHub

Description

tar (node-tar) fails to strip attacker-controlled NUL bytes from archive-derived path and linkpath strings when a line terminator (CR or LF) appears between an earlier and a later NUL. The sanitization guard /\0.*/ uses a bare dot, which does not match line terminators, so everything from the first line terminator onward is preserved, including NUL bytes. A NUL-bearing path then reaches Node.js filesystem APIs during asynchronous extraction. Node core rejects such arguments with ERR_INVALID_ARG_VALUE, and the throw occurs inside node-tar's async continuation (FSReqCallback.oncomplete chain), where no node-tar code catches it. The exception surfaces as uncaughtException and terminates the extracting process. An attacker who can supply an archive to any process that extracts it with the default asynchronous tar.x / tar.extract API gains a one-archive process-crash primitive. Consumers that correctly wrap the call in try { await tar.x(...) } catch are not protected.

This is an incomplete fix of GHSA-gvwx-54wh-qm9j (CVE-2026-59875). The patched statement in src/pax.ts (kv.join('=').replace(/\0.*/, '')) is bypassable as described, and the same flawed idiom remains in the two sibling sinks that the advisory cited as the correct reference implementation (src/parse.ts GNU L/K handling and src/header.ts decString), which were never covered by the advisory and remain exploitable in the current release.

Details

Three source locations terminate archive-controlled strings at the first NUL using the regex /\0.*/:

// src/pax.ts:179 (line patched by the 7.5.17 fix for GHSA-gvwx)
const v = kv.join('=').replace(/\0.*/, '')

// src/parse.ts:390 (GNU L long path)
ex.path = this[META].replace(/\0.*/, '')

// src/parse.ts:397 (GNU K long linkpath)
ex.linkpath = this[META].replace(/\0.*/, '')

// src/header.ts:354-358 (decString, used for all raw ustar header fields)
const decString = (buf: Buffer, off: number, size: number) =>
  buf
    .subarray(off, off + size)
    .toString('utf8')
    .replace(/\0.*/, '')

In JavaScript regex, a bare . matches any character except line terminators (\n, \r, \u2028, \u2029). The match /\0.*/ therefore ends at the first line terminator after the first NUL instead of at the end of the string, and replace preserves the remainder, including any NUL bytes after the terminator.

Data flow for the primary variant (PAX, bypassing the 7.5.17 patch):

  1. The archive contains an x typeflag extended header whose body holds the record p\0q\r\0r with a valid record length prefix. parseKVLine accepts the record and assigns v = 'p\0q\r\0r' (src/pax.ts:157-208).
  2. v.replace(/\0.*/, '') removes \0q, stops at \r, and yields 'p\r\0r'. The NUL at index 2 survives (src/pax.ts:179).
  3. Header.decode applies PAX-provided fields verbatim without decString: this.path = exForFields?.path ?? decString(buf, off, 100) (src/header.ts:100). ReadEntry copies the value: this.path = normalizeWindowsPath(header.path), which is the identity function on POSIX (src/read-entry.ts:85).
  4. Unpack sanitization does not reject NUL. [CHECKPATH] splits on /, looks only for .. segments and absolute roots (src/unpack.ts:320-404). path.resolve(cwd, entry.path) accepts embedded NULs because path resolution performs no filesystem access. The containment check (entry.absolute.indexOf(this.cwd + '/') !== 0) passes since the NUL appears after the cwd prefix.
  5. [CHECKFS2] calls fs.lstat(String(entry.absolute)) (src/unpack.ts:774) inside an MKDIR completion callback. Node core validates the argument and throws TypeError [ERR_INVALID_ARG_VALUE] synchronously inside the FSReqCallback.oncomplete continuation. No node-tar code in that stack is wrapped, so the exception becomes uncaughtException and the process dies. An error event handler on the Unpack stream does not intercept it.

The raw-header and GNU L variants follow the same flow but need no PAX at all. For a plain ustar header whose 100 byte path field contains a, NUL, b, CR, c, NUL, d, decString yields 'a\rc\0d', again with a surviving NUL. GNU L bodies behave identically through src/parse.ts:390, the exact line the advisory described as the correctly patched reference.

Synchronous extraction (UnpackSync) is not affected: every filesystem call there is wrapped by local try/catch blocks and surfaces as a TAR_ENTRY_ERROR warning, so the archive fails closed. tar.t / tar.list never touches the filesystem and does not crash, but it emits the NUL-bearing path, which also preserves the parser-differential concern raised in the predecessor advisory: tools that truncate at the first NUL (GNU tar, bsdtar) observe a different name than node-tar retains.

PoC

node-tar-nul-termination-bypass-PoC.zip

See the attached PoC zip. Summary:

./deployment/deploy.sh     # stages a sandbox with pinned tar@7.5.22
./poc/poc.sh               # builds six archives and runs the assertions

poc.sh prints one PASS line per assertion and ends with RESULT: 8 passed, 0 failed on the affected version. It includes a benign control, the original advisory payload (clean since 7.5.17), the CR bypass variant, two raw-header variants (CR and LF), a GNU L variant, and negative controls proving that sync extraction and listing do not crash. Full executed output is in the zip's README.md.

A minimal single-archive reproduction: build a tar whose first entry is an x extended header containing the record 15 path=p\0q\r\0r (valid length prefix), followed by a normal file header, then run tar.extract({ cwd }) asynchronously. On tar@7.5.22 the process dies with ERR_INVALID_ARG_VALUE naming the path <cwd>/p\r\x00r.

Impact

Remote denial of service. Any service that extracts attacker-supplied archives through the default asynchronous API (npm package ingestion, CI artifact processing, upload processing, backup restore) can be terminated by a single small archive. The throw bypasses correct consumer error handling because it is raised outside the returned promise and outside the stream error event. The crash happens at the first lstat before any filesystem mutation, so there is no file integrity or data exposure impact, and the availability impact is the demonstrated primitive.

The same sanitization defect also lets archive paths retain NUL bytes where other tar implementations truncate at the first NUL, which preserves the parser-differential (CWE-436) exposure described for the predecessor advisory.

Affected versions

References

GitHub · isaacs/node-tar