fix: guard crypto.randomUUID for insecure origins (toast store, message-id, contact uid) - #888
Open
texchi2 wants to merge 2 commits into
Open
fix: guard crypto.randomUUID for insecure origins (toast store, message-id, contact uid)#888texchi2 wants to merge 2 commits into
texchi2 wants to merge 2 commits into
Conversation
… undefined) — use guarded generateUUID(); send failed after draft save, before EmailSubmission
…ined), breaking every post-action acknowledgement addToast() minted toast ids with crypto.randomUUID(), which only exists in secure contexts (https/localhost). On a plain-http LAN origin every toast.success/toast.error threw a TypeError, so e.g. calendar event Save crashed AFTER a successful CalendarEvent/set — before the dialog-close ran — leaving the dialog open reporting failure while the server had the event; retries created duplicates. Same class as the generateMessageId send bug. Also guards the same-class contact uid fallback in lib/jmap/client.ts (createContact). Both now use the guarded generateUUID() from lib/utils. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MtFkcUA8VM2XAKZKzptpqy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #887 (calendar Save reports failure while the event is created; duplicates on retry) and the same-class silent compose-Send failure.
Root cause
crypto.randomUUIDis[SecureContext]-gated — on a plain-http LAN origin (a common self-hosted pilot deployment) it isundefined, and three call sites called it unguarded:stores/toast-store.tsaddToast()— everytoast.success/toast.errorthrewTypeError: crypto.randomUUID is not a function. InhandleSaveEventthe success toast runs before the dialog-close, so a successfulCalendarEvent/setwas followed by a throw; the catch'stoast.errorthrew again uncaught; the dialog stayed open reporting failure while the server had the event, and user retries created duplicates.lib/jmap/client.tsgenerateMessageId()— compose Send failed silently after the draft save, beforeEmailSubmissionwas ever issued (drafts piled up).lib/jmap/client.tscreateContactuid fallback — contact creation without a uid crashed pre-request.Fix
All three now use the guarded
generateUUID()already inlib/utils.ts(typeof-check, falling back to a v4 UUID built fromcrypto.getRandomValues, which insecure contexts do provide).Verification
Headless-Chromium reproduction on an insecure origin (
isSecureContext === false), logged into a real JMAP server (Stalwart 0.16):TypeErroratObject.addToast(viatoast.error), dialog stays open, server has exactly 1 new event.generateMessageIdguard.Not touched, flagged for a follow-up: unguarded
crypto.subtle.digestinlib/oauth/pkce.tsandlib/plugin-sandbox/bundle-integrity.ts(same class, separate feature paths), andnavigator.clipboardabsence on insecure origins in the copy-link paths (try/caught; degrades gracefully once toasts work).🤖 Generated with Claude Code
https://claude.ai/code/session_01MtFkcUA8VM2XAKZKzptpqy