Skip to content

Commit 87d9f79

Browse files
committed
fix(security)(utils): predictable global cache directory in /tmp enables
The cache directory is a fixed, shared path (`/tmp/ncc-cache`). On multi-user systems this can be pre-created or manipulated by another user (symlink/hardlink attacks), potentially causing cache poisoning, unintended file writes, or data leakage between builds/users depending on how cache files are later written. Affected files: ncc-cache-dir.js Signed-off-by: tuanaiseo <221258316+tuanaiseo@users.noreply.github.com>
1 parent 91ba339 commit 87d9f79

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/utils/ncc-cache-dir.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
module.exports = require("os").tmpdir() + "/ncc-cache";
1+
const crypto = require("crypto");
2+
const os = require("os");
3+
const path = require("path");
4+
5+
const cacheBase = process.env.XDG_CACHE_HOME || path.join(os.homedir(), ".cache");
6+
const projectKey = crypto.createHash("sha256").update(process.cwd()).digest("hex").slice(0, 12);
7+
8+
module.exports = path.join(cacheBase, "ncc", projectKey);

0 commit comments

Comments
 (0)