Skip to content

Commit cfb0f6c

Browse files
os-zhuangclaude
andcommitted
test(cli): use mkdtempSync for runtime-assets temp dir
CodeQL flagged js/insecure-temporary-file (high) on the test: it built a temp dir from a predictable `Date.now()` name and wrote into it, which is open to a temp-file race / symlink attack in the shared OS temp dir. Use fs.mkdtempSync() to atomically create a uniquely-named directory with a random suffix — the pattern CodeQL recognizes as safe — and drop the now redundant mkdirSync. Behavior is otherwise unchanged; all 3 tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 045fcf8 commit cfb0f6c

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

packages/cli/test/runtime-assets.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ import os from 'os';
1313
import path from 'path';
1414
import { createRuntimeAssetsPlugin } from '../src/utils/console.js';
1515

16-
const assetsDir = path.join(os.tmpdir(), `os-test-runtime-assets-${Date.now()}`);
16+
// Atomically create a uniquely-named temp dir (random suffix) instead of a
17+
// predictable `Date.now()` name — avoids the temp-file race/symlink attack
18+
// flagged by CodeQL js/insecure-temporary-file.
19+
const assetsDir = fs.mkdtempSync(path.join(os.tmpdir(), 'os-test-runtime-assets-'));
1720
const testPng = path.join(assetsDir, 'test-logo.png');
1821

1922
beforeAll(() => {
20-
fs.mkdirSync(assetsDir, { recursive: true });
2123
fs.writeFileSync(testPng, Buffer.from('fake-png-content'));
2224
});
2325

0 commit comments

Comments
 (0)