From b64318d9e8ff998ef44ab0e61ec4117bd5ed4ae0 Mon Sep 17 00:00:00 2001 From: henrygd Date: Sun, 24 Aug 2025 17:22:48 -0400 Subject: [PATCH] fix: frontend token generation in insecure contexts --- beszel/site/src/lib/utils.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/beszel/site/src/lib/utils.ts b/beszel/site/src/lib/utils.ts index d80aa45..a143bda 100644 --- a/beszel/site/src/lib/utils.ts +++ b/beszel/site/src/lib/utils.ts @@ -442,7 +442,13 @@ export const alertInfo: Record = { export const getHostDisplayValue = (system: SystemRecord): string => system.host.slice(system.host.lastIndexOf("/") + 1) /** Generate a random token for the agent */ -export const generateToken = () => crypto?.randomUUID() ?? (performance.now() * Math.random()).toString(16) +export const generateToken = () => { + try { + return crypto?.randomUUID() + } catch (e) { + return Array.from({ length: 2 }, () => (performance.now() * Math.random()).toString(16).replace(".", "-")).join("-") + } +} /** Get the hub URL from the global BESZEL object */ export const getHubURL = () => BESZEL?.HUB_URL || window.location.origin