Skip to content

Commit 7f0f6b0

Browse files
committed
TCLOUD-4780: Use crypto to make the temporary file name unpredictable
Note that this doesn't prevent the file being rewriten after it has been created but as we have to pass the file to other processes that can't be prevented.
1 parent fae80ad commit 7f0f6b0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

.github/workflows/scripts/generate_redirects.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import crypto from 'node:crypto';
12
import fs from 'node:fs';
3+
import os from 'node:os';
24
import path from 'node:path';
35
import { spawn } from 'node:child_process';
46

@@ -166,7 +168,7 @@ function* generateRedirectObjectsAsync(dryRun, bucket, prefix, redirectsByLocati
166168
</html>`;
167169

168170
// Write temporary file
169-
const newFileTemplate = `/tmp/redirect-${Date.now()}.html`;
171+
const newFileTemplate = path.join(os.tmpdir(), `redirect-${crypto.randomBytes(16).toString('hex')}.html`);
170172
fs.writeFileSync(newFileTemplate, htmlContent);
171173

172174
let allSettled = Promise.resolve();

0 commit comments

Comments
 (0)