Miggo Logo

CVE-2025-54798: tmp allows arbitrary temporary file / directory write via symbolic link `dir` parameter

2.5

CVSS Score
3.1

Basic Information

EPSS Score
-
Published
8/6/2025
Updated
8/6/2025
KEV Status
No
Technology
TechnologyJavaScript

Technical Details

CVSS Vector
CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:L/A:N
Package NameEcosystemVulnerable VersionsFirst Patched Version
tmpnpm<= 0.2.30.2.4

Vulnerability Intelligence
Miggo AIMiggo AI

Miggo AIRoot Cause Analysis

The vulnerability exists because the tmp library did not correctly handle symbolic links when validating user-provided directory paths. The root cause is in the _resolvePath function, which used path.resolve instead of a function that resolves symbolic links, like fs.realpathSync. This allowed an attacker to specify a dir option that is a symbolic link pointing to a location outside of the intended temporary directory, bypassing the security checks in _assertIsRelative.

The exploitation of this vulnerability occurs through user-facing functions like fileSync, dirSync, and their asynchronous counterparts (file, dir), which all rely on the flawed path validation logic. The provided patch addresses the issue by removing the vulnerable _resolvePath and _assertIsRelative functions and replacing them with new logic (_resolvePathSync, _getRelativePathSync) that correctly resolves symbolic links using fs.realpathSync before performing the validation checks. Therefore, any function that creates temporary files or directories using a user-supplied dir option was vulnerable.

Vulnerable functions

_resolvePath
lib/tmp.js
This function is the core of the vulnerability. It attempts to resolve a path to ensure it's within the temporary directory, but it uses `path.resolve`, which does not resolve symbolic links. An attacker can provide a `dir` option that is a symlink to a directory outside of the temporary directory, thus bypassing the check and allowing file creation in an arbitrary location. The function was entirely removed and replaced with a new implementation that uses `fs.realpathSync`.
_assertIsRelative
lib/tmp.js
This function uses the vulnerable `_resolvePath` function to check if the `dir` or `template` options are relative to the system's temporary directory. Because `_resolvePath` can be bypassed using a symbolic link, this check is ineffective, making `_assertIsRelative` a key component of the vulnerability. This function was removed in the patch.
tmpNameSync
lib/tmp.js
This synchronous function is one of the main entry points for the vulnerability. It calls `_assertAndSanitizeOptions`, which in turn uses the vulnerable path resolution logic. An attacker calling `tmpNameSync` (or a function that uses it, like `fileSync`) with a malicious `dir` option would trigger the vulnerability. The patch replaces the call to the old, vulnerable sanitization function with a new, secure one (`_assertAndSanitizeOptionsSync`).
fileSync
lib/tmp.js
As demonstrated in the Proof of Concept, `fileSync` is a user-facing function that can be used to exploit this vulnerability. It internally calls `tmpNameSync` to generate a temporary file path, which triggers the vulnerable path resolution and validation logic. Any runtime profile of the exploit would likely show `fileSync` in the call stack.
dirSync
lib/tmp.js
Similar to `fileSync`, `dirSync` is another user-facing function that uses the vulnerable `tmpNameSync` function. It can be used to create a temporary directory in an arbitrary location by exploiting the symbolic link vulnerability in the `dir` option.

WAF Protection Rules

WAF Rule

### Summ*ry `tmp@*.*.*` is vuln*r**l* to *n *r*itr*ry t*mpor*ry *il* / *ir**tory writ* vi* sym*oli* link `*ir` p*r*m*t*r. ### **t*ils ***or*in* to t** *o*um*nt*tion t**r* *r* som* *on*itions t**t must ** **l*: ``` // *ttps://*it*u*.*om/r*szi/no*

Reasoning

T** vuln*r**ility *xists ****us* t** `tmp` li*r*ry *i* not *orr**tly **n*l* sym*oli* links w**n v*li**tin* us*r-provi*** *ir**tory p*t*s. T** root **us* is in t** `_r*solv*P*t*` *un*tion, w*i** us** `p*t*.r*solv*` inst*** o* * *un*tion t**t r*solv*s