From bf4dd6c47013a83019c0ca44478804a5869edb14 Mon Sep 17 00:00:00 2001 From: Diego Imbert Date: Mon, 8 Jun 2026 19:32:09 +0200 Subject: [PATCH] fix(drafts): swap crypto.randomUUID() for the project's randomUUID helper crypto.randomUUID() is gated on a secure origin (HTTPS or localhost). Self-hosted Windmill instances often run on a bare HTTP origin or a LAN IP where the WebCrypto API is unavailable, so the /add redirect would throw before issuing the 307. Use the existing RFC4122 v4 helper in FlowChatManager that the rest of the codebase already imports for this exact reason. --- frontend/src/lib/draftAddRedirect.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/draftAddRedirect.ts b/frontend/src/lib/draftAddRedirect.ts index 27584a4627..4a948a46f3 100644 --- a/frontend/src/lib/draftAddRedirect.ts +++ b/frontend/src/lib/draftAddRedirect.ts @@ -1,6 +1,7 @@ import { redirect } from '@sveltejs/kit' import { base } from '$app/paths' import { getUsernameForNamespace } from '$lib/userNamespace' +import { randomUUID } from '$lib/components/flows/conversations/FlowChatManager.svelte' /** * Shared `load` for every `/{scripts,flows,apps,apps_raw}/add` route. @@ -14,11 +15,16 @@ import { getUsernameForNamespace } from '$lib/userNamespace' * `{base}/{editPrefix}/?new_draft=true&`. * The `new_draft=true` flag tells the edit route to seed an empty * editor instead of 404-ing on the autogenerated path. + * + * Uses the project's `randomUUID` helper rather than + * `crypto.randomUUID()` — the WebCrypto version is unavailable on + * non-secure origins (HTTP, local IPs over LAN), and self-hosted + * Windmill instances frequently run that way. */ export function makeDraftAddLoad(editPrefix: string) { return ({ url }: { url: URL }) => { const username = getUsernameForNamespace() - const uuid = crypto.randomUUID() + const uuid = randomUUID() const params = new URLSearchParams(url.searchParams) params.set('new_draft', 'true') redirect(307, `${base}/${editPrefix}/u/${username}/draft_${uuid}?${params.toString()}`)