The tmp package's _assertPath function does one thing. It calls path.includes('..') on the caller-supplied prefix, postfix, or template and throws if the substring is found. The check was added in lib/tmp.js on April 6, 2026 as the response to a prior path-traversal advisory; the author wrote it for strings, and JavaScript also exposes .includes on Array.prototype, where the method checks element equality rather than substring presence. CVE-2026-49982 is what the gate does when the caller's prefix is ['../escape'].
CVE-2026-49982: tmp's _assertPath Called .includes('..'). Array.prototype.includes Is Element Equality.
vendor
patterns
cve
proof of concept
The gate was the previous fix
The function that fails in tmp 0.2.6 did not exist in 0.2.5. Commit 7ef2728 (April 6, 2026), titled "Check for relative values," is upstream maintainer KARASZI István's response to GHSA-ph9p-34f9-6g65, an earlier path-handling advisory against the same package. The commit adds a five-line helper to lib/tmp.js:
function _assertPath(path) {
if (path.includes("..")) {
throw new Error("Relative value not allowed");
}
return path;
}The same commit wires _assertPath into _assertOptionsBase for the three caller-controlled name fragments:
options.prefix = _isUndefined(options.prefix) ? '' : _assertPath(options.prefix);
options.postfix = _isUndefined(options.postfix) ? '' : _assertPath(options.postfix);
options.template = _isUndefined(options.template) ? undefined : _assertPath(options.template);tmp is the temporary-file generator that has lived in the dependency graph of build tools, test runners, CLI scaffolds, and ORMs since 2011. Its documented API accepts prefix, postfix, and template as user-controllable strings that contribute to the generated path. The 0.2.6 patch is the maintainer's commitment that those strings cannot contain ... The commitment is encoded as .includes('..'). The two diverge on the first non-string the caller sends.
Array.prototype.includes is element equality
String.prototype.includes(substring) returns true when the argument appears as a contiguous substring of the receiver. Array.prototype.includes(searchElement) returns true when the argument is ===-equal (more precisely, SameValueZero) to any element of the receiver. They share a name. They do not share a contract.
The PoC published with the advisory is one line:
tmp.fileSync({ tmpdir: baseDir, prefix: ['../escape'] });_assertPath(['../escape']) evaluates ['../escape'].includes(".."). The array has one element, the string '../escape'. The element is not strictly equal to '..'. The check returns false; the throw is skipped; the function returns the array unchanged.
_assertOptionsBase writes the array back into options.prefix and the call proceeds into _generateTmpName:
function _generateTmpName(opts) {
const tmpDir = opts.tmpdir;
if (!_isUndefined(opts.name)) {
return path.join(tmpDir, opts.dir, opts.name);
}
if (!_isUndefined(opts.template)) {
return path.join(tmpDir, opts.dir, opts.template).replace(TEMPLATE_PATTERN, _randomChars(6));
}
// prefix and postfix
const name = [
opts.prefix ? opts.prefix : 'tmp',
'-',
process.pid,
'-',
_randomChars(12),
opts.postfix ? '-' + opts.postfix : ''
].join('');
return path.join(tmpDir, opts.dir, name);
}The outer array now contains a nested array at index 0. Array.prototype.join('') invokes the String abstract operation on each element. For an array, String([...]) is [...].toString(), which is [...].join(','). The inner ['../escape'] flattens to the literal string '../escape'. The resulting name reads ../escape-<pid>-<12 random hex chars>.
path.join(tmpDir, opts.dir, name) resolves the leading .. against tmpDir's parent. The file lands one directory above the temporary base the caller asked for. The caller did not see the array stringify; the caller did not see the path resolve; the caller sees a tmp.fileSync call that returned successfully with a path one directory outside the sandbox they passed in.
The duck-typed object case is the same primitive on a different shape: { includes: () => false, toString: () => '../escape' } defeats the check with a custom .includes method that returns false unconditionally, and supplies the traversal payload through the same toString coercion Array.prototype.join performs on every element. The gate calls the receiver's own .includes. The receiver decides what .includes returns.
The pattern is Gate Before Canonicalize
The shape repeats across the catalog: a security check inspects the input for a forbidden form, a downstream subsystem canonicalizes the same input into that forbidden form, and the input crosses the boundary between the two by carrying a representation neither parser shared with the other.
Most prior exhibits of gate-before-canonicalize live in HTTP routing. Alfresco's regex denylist that missed ..;/ because Tomcat parses path parameters after the check runs. Spring's uriDecode truncating sixteen-bit chars before its own gate inspected the result. Gotenberg's case-sensitive regex against HTTPS:// that net/url.Parse lowercased on the way to the dial. The two parses each lived in a different component; the attacker rode the disagreement between them.
CVE-2026-49982 is the same shape on a different substrate. The canonicalizer is not URL parsing. It is JavaScript's automatic string coercion via Array.prototype.join. The gate ran .includes('..') against the array shape; the downstream _generateTmpName ran path.join against the string the same array stringifies to. Two parses, one function, the disagreement reified as the difference between Array.prototype.includes and String.prototype.includes.
The closest sibling on the catalog is vm2 CVE-2026-43998, which puts the pattern on path.resolve versus fs.realpathSync inside Node's require. Both exhibits live in the same language. Both involve a gate written against one of two coexisting representations of the same logical value. In vm2 the two representations were the lexical path and its symlink-resolved form. In tmp the two are the array literal and its string coercion.
What the April patch did not catch
0.2.6's security commit added more than _assertPath. The same commit reworked _getRelativePath and _getRelativePathSync to verify that the resolved path does not escape tmpdir after the name is built:
const relativePath = path.relative(tmpDir, resolvedPath);
if (relativePath.startsWith('..') || path.isAbsolute(relativePath)) {
throw new Error(`${option} option must be relative to "${tmpDir}", found "${relativePath}".`);
}That is the defense-in-depth. If the gate misses, the path-relative check is supposed to catch the escape after the path has been resolved. The check is real. It is wired into options.dir, options.template, and options.name. It is not wired into options.prefix or options.postfix.
prefix and postfix flow into _generateTmpName's inline name-builder and from there directly into path.join(tmpDir, opts.dir, name). There is no post-resolution verification step on the way out. The 0.2.6 patch added a perimeter check (_assertPath) and an interior check (_getRelativePath); the interior check covers three of the five caller-controlled fields and the perimeter check is the only thing between the array bypass and the file system.
For template, the secondary check would in principle catch a bypass that reached it. In practice, an Array-shaped template throws a TypeError earlier, at options.template.match(TEMPLATE_PATTERN), because Array.prototype.match does not exist. The 0.2.7 fix addresses this same match call by inserting the same typeof check ahead of it. The exploitable primitive on 0.2.6 is the prefix or postfix path, where neither the secondary check nor the regex match stands between the gate and the file system.
The fix monomorphises the gate
Commit ce787f3 (May 27, 2026), authored by tonghuaroot, is the patch for the patch. It rewrites _assertPath to require its argument to be a string before the substring check runs:
-function _assertPath(path) {
- if (path.includes("..")) {
+function _assertPath(option, value) {
+ if (typeof value !== 'string') {
+ throw new Error(`${option} option must be a string, got "${typeof value}".`);
+ }
+
+ if (value.includes("..")) {
throw new Error("Relative value not allowed");
}
- return path;
+ return value;
}The structural move matches the resolution prior gate-before-canonicalize exhibits chose: refuse the input shapes the two parsers disagree about, leave the rest of the pipeline alone. tmp 0.2.7 does not change _generateTmpName, does not change _getRelativePath, does not change path.join. It removes the polymorphism by narrowing the gate's argument to the one type the gate was written for. The check that was written assuming string semantics now runs only against strings.
The April 6 commit author is the project maintainer. The May 27 commit author is a separate researcher who reported the bypass, supplied the patch, and got the advisory credit. Seven weeks separate the gate's introduction from the gate's narrowing. The package's prior advisory was the one 0.2.6 was the response to; the advisory before that (GHSA-52f5-9888-hmc6) was a different path-handling primitive in the same neighborhood of lib/tmp.js, fixed in April 2025. Three GHSAs in the same component in fourteen months, each fix exposing the next. The design-debt driver is the inline name-builder array at the bottom of _generateTmpName: caller-supplied values flow into path.join through Array.prototype.join('') with no type discipline at the boundary, and every gate the maintainers have shipped is a perimeter check on the shape of the demonstrated bypass rather than a refactor of the builder.
The patch narrowed the gate to the type it was written for. The two .includes methods that disagree about what .. means are both still in the standard library.