diff --git a/src/cron/run-log.ts b/src/cron/run-log.ts index 18d5f22d4..bcb27c9e1 100644 --- a/src/cron/run-log.ts +++ b/src/cron/run-log.ts @@ -36,7 +36,8 @@ async function pruneIfNeeded(filePath: string, opts: { maxBytes: number; keepLin .map((l) => l.trim()) .filter(Boolean); const kept = lines.slice(Math.max(0, lines.length - opts.keepLines)); - const tmp = `${filePath}.${process.pid}.${Math.random().toString(16).slice(2)}.tmp`; + const { randomBytes } = await import("node:crypto"); + const tmp = `${filePath}.${process.pid}.${randomBytes(8).toString("hex")}.tmp`; await fs.writeFile(tmp, `${kept.join("\n")}\n`, "utf-8"); await fs.rename(tmp, filePath); } diff --git a/src/cron/store.ts b/src/cron/store.ts index cfc2044df..68f2e225c 100644 --- a/src/cron/store.ts +++ b/src/cron/store.ts @@ -49,7 +49,8 @@ export async function loadCronStore(storePath: string): Promise { export async function saveCronStore(storePath: string, store: CronStoreFile) { await fs.promises.mkdir(path.dirname(storePath), { recursive: true }); - const tmp = `${storePath}.${process.pid}.${Math.random().toString(16).slice(2)}.tmp`; + const { randomBytes } = await import("node:crypto"); + const tmp = `${storePath}.${process.pid}.${randomBytes(8).toString("hex")}.tmp`; const json = JSON.stringify(store, null, 2); await fs.promises.writeFile(tmp, json, "utf-8"); await fs.promises.rename(tmp, storePath); diff --git a/src/tts/tts.ts b/src/tts/tts.ts index becdf7bfc..85f3454c3 100644 --- a/src/tts/tts.ts +++ b/src/tts/tts.ts @@ -1,3 +1,4 @@ +import { randomBytes } from "node:crypto"; import { existsSync, mkdirSync, @@ -382,8 +383,8 @@ function readPrefs(prefsPath: string): TtsUserPrefs { } function atomicWriteFileSync(filePath: string, content: string): void { - const tmpPath = `${filePath}.tmp.${Date.now()}.${Math.random().toString(36).slice(2)}`; - writeFileSync(tmpPath, content); + const tmpPath = `${filePath}.tmp.${Date.now()}.${randomBytes(8).toString("hex")}`; + writeFileSync(tmpPath, content, { mode: 0o600 }); try { renameSync(tmpPath, filePath); } catch (err) {