security: use crypto.randomUUID for temp file suffix (SonarCloud S2245)

Replace Math.random() with crypto.randomUUID() when generating the unique
suffix for the atomic write-then-move temp file. The value isn't security-
sensitive, but a CSPRNG gives a stronger uniqueness guarantee and resolves
SonarCloud javascript:S2245.
This commit is contained in:
Dylan M. Taylor
2026-10-21 17:14:27 -04:00
parent cee4c16c8a
commit 887fe3a3a8
+1 -1
View File
@@ -495,7 +495,7 @@ export async function cacheRead(name) {
export async function cacheWrite(fullName, bytes) {
const [dir, name] = await entryDir(fullName);
const canMove = typeof FileSystemHandle !== "undefined" && "move" in FileSystemHandle.prototype;
const tmp = canMove ? `${name}.tmp.${Math.random().toString(36).slice(2)}` : name;
const tmp = canMove ? `${name}.tmp.${crypto.randomUUID()}` : name;
const fh = await dir.getFileHandle(tmp, { create: true });
if (fh.createSyncAccessHandle) {
const h = await fh.createSyncAccessHandle();