The vulnerability is a type-confusion issue in the tmp library, specifically within the _assertPath function. This function was designed to prevent path traversal attacks by checking for .. in user-supplied options like prefix, postfix, and template. However, it did not verify that the input was a string before performing the check.
An attacker can exploit this by providing a non-string value, such as a JavaScript array (e.g., ['../escape']). The Array.prototype.includes('..') method checks for the literal element '..' in the array, which is not present, so the check passes. Subsequently, in the _generateTmpName function, this array is joined into a string, re-forming the malicious path ../escape.
The vulnerable execution flow starts when a user-facing function like tmp.file() or tmp.dir() is called with malicious options. These options are processed by _assertOptionsBase, which then calls the flawed _assertPath. The bypassed value is then used in _generateTmpName to construct a path outside the intended temporary directory.
The patch addresses this by modifying _assertPath to strictly enforce that its input is a string, throwing an error if it is not. This ensures the .includes('..') check is always performed on a string, effectively preventing the type-confusion bypass.