mirror of
https://github.com/storytold/effectcraft.git
synced 2026-10-24 10:09:32 -06:00
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user