Repository navigation
fix(web): make Add Section work on insecure (plain-HTTP) origins - #458
Conversation
Both add-section paths on Settings > Home Screen called crypto.randomUUID() unguarded. Browsers only expose randomUUID in secure contexts, so on self-hosted servers accessed over plain HTTP the click handler threw synchronously and the Add section button appeared dead while Cancel still worked. api/client.ts and plexAuth.ts already carried ad-hoc fallbacks for the same problem; extract a shared lib/uuid helper (UUIDv4 via crypto.getRandomValues, available in insecure contexts) and use it at all four call sites. Co-Authored-By: Claude Fable 5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughA shared ChangesUUID Generation Centralization
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@web/src/lib/uuid.ts`:
- Line 23: Format the UUID return expression in the UUID generation function so
it complies with the frontend formatter’s 100-character line width, preserving
the existing interpolated UUID segments and output.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ee32d950-3ce3-4c56-908a-c6d54c3784eb
📒 Files selected for processing (5)
web/src/api/client.tsweb/src/components/sections/SectionEditorDrawer.tsxweb/src/lib/plexAuth.tsweb/src/lib/uuid.tsweb/src/pages/settings/HomeScreenSettings.tsx
Addresses CodeRabbit review on PR #458. Co-Authored-By: Claude Fable 5 <[email protected]>
Problem
Reported via an internal Discord thread (build
0a914441): on Settings → Home Screen, neither "Add Section" nor "Add from gallery" can actually add a section — the "Add section" button appears completely dead while Cancel still works. Happens every time on the reporting deployment.Root cause
buildProfileGallerySection(HomeScreenSettings.tsx) andbuildProfileSectionSaveEntry(SectionEditorDrawer.tsx) callcrypto.randomUUID()unguarded. Browsers only exposecrypto.randomUUIDin secure contexts, so on a self-hosted server accessed over plain HTTP (typical LAN/docker setup) the call throwsTypeErrorsynchronously inside the click handler. Nothing visible happens: the drawer stays open (gallery flow) or closes without adding (editor flow), and only Cancel responds — exactly the reported symptom.The codebase already knew about this failure mode:
api/client.ts(device ID) andlib/plexAuth.ts(Plex client ID) both carry ad-hoctypeof crypto.randomUUID === "function"fallbacks — which is why everything else works over HTTP and only these two buttons break.ProfileCustomizeHomeis unaffected because the server assigns IDs there.Fix
web/src/lib/uuid.ts—randomUUID()usescrypto.randomUUIDwhen available and otherwise generates an RFC 4122 v4 UUID viacrypto.getRandomValues, which is available in insecure contexts (with aMath.randomlast resort).api/client.tsandlib/plexAuth.tswith the same helper (removes non-UUID-shapedweb-…/silo-…fallback IDs; existing stored IDs are untouched).getOrCreateDeviceIdcan no longer returnnull, so the dead null-branch ingetDeviceHeadersis dropped.Server-side, section override IDs are opaque strings, so client-generated v4 UUIDs remain fully compatible.
Validation
pnpm run lint,pnpm run format:check,tsc -b: clean.crypto.randomUUIDabsent: 1000/1000 unique, valid v4-format UUIDs.Risks / follow-ups
None expected; change is additive and confined to ID generation. Clients on secure origins keep using native
crypto.randomUUID.Disclosure
Diagnosed and implemented with AI assistance (Claude Code); reviewed by a human before merge.
🤖 Generated with Claude Code
Summary by CodeRabbit