From d77dd1e3e1d17a364146cf5caf79e9020de6a8f5 Mon Sep 17 00:00:00 2001 From: Linus Rath <139418639+rathlinus@users.noreply.github.com> Date: Thu, 2 Apr 2026 17:25:10 +0200 Subject: [PATCH] fix: replace non-UUID fallback --- lib/utils.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/utils.ts b/lib/utils.ts index a9b03047..d489d1d3 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -11,7 +11,13 @@ export function generateUUID(): string { if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') { return crypto.randomUUID(); } - return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`; + // Fallback: construct a v4 UUID from crypto.getRandomValues + const bytes = new Uint8Array(16); + crypto.getRandomValues(bytes); + bytes[6] = (bytes[6] & 0x0f) | 0x40; // version 4 + bytes[8] = (bytes[8] & 0x3f) | 0x80; // variant 1 + const hex = Array.from(bytes, b => b.toString(16).padStart(2, '0')).join(''); + return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`; } export function formatDate(date: Date | string): string {