Skip to content

fix: fall back to getRandomValues for UUIDs on insecure origins - #64

Merged
ymansurozer merged 1 commit into
mainfrom
fix/0015-ui-uuid-fallback
Jul 21, 2026
Merged

fix: fall back to getRandomValues for UUIDs on insecure origins#64
ymansurozer merged 1 commit into
mainfrom
fix/0015-ui-uuid-fallback

Conversation

@ymansurozer

Copy link
Copy Markdown
Owner

Problem

crypto.randomUUID() is secure-context-gated: browsers expose it only on HTTPS origins and on localhost/127.0.0.1. On a desk bound beyond loopback (GALLEY_HOST, the tailnet/devbox pattern) the UI loads from a plain-HTTP non-localhost origin like http://devbox:41443/, where crypto.randomUUID is undefined — so the first comment attempt throws and the whole comment/change-request loop is broken. It never reproduces locally because localhost counts as a secure context.

Fix

  • New src/ui/uuid.ts: uuid() uses native crypto.randomUUID() when present, otherwise uuidFallback() builds an RFC-4122 v4 UUID from crypto.getRandomValues() (available in insecure contexts) with the version (4) and variant (10xx) bits set, so the fallback is indistinguishable in shape from native ids that persist in review state.
  • src/ui/main.ts: the comment-creation path (the only secure-context-gated call site in src/ui/) now uses uuid().
  • src/ui/uuid.test.ts: fallback matches the v4 format, successive calls differ, uuid() works with randomUUID absent, and the native path is still used when available.

Node-side randomUUID call sites (src/state.ts, src/server.ts) are unconditional and untouched.

Closes .desk issue 0015.

🤖 Generated with Claude Code

crypto.randomUUID() is secure-context-gated, so it's undefined on
plain-HTTP non-localhost desks (GALLEY_HOST/tailnet), and creating a
comment threw. Add a uuid() helper that uses the native call when
present and otherwise builds an RFC-4122 v4 UUID from
crypto.getRandomValues(), which has no such gate.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ymansurozer
ymansurozer force-pushed the fix/0015-ui-uuid-fallback branch from 30c00dc to 312fa31 Compare July 21, 2026 11:22
@ymansurozer
ymansurozer merged commit 1467b08 into main Jul 21, 2026
1 check passed
@ymansurozer
ymansurozer deleted the fix/0015-ui-uuid-fallback branch July 21, 2026 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant