Skip to content

fix(web): make Add Section work on insecure (plain-HTTP) origins - #458

Merged
Quick104 merged 2 commits into
mainfrom
fix/section-add-insecure-context
Jul 23, 2026
Merged

Quick104 merged 2 commits into
mainfrom
fix/section-add-insecure-context

Conversation

@Quick104

@Quick104 Quick104 commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

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) and buildProfileSectionSaveEntry (SectionEditorDrawer.tsx) call crypto.randomUUID() unguarded. Browsers only expose crypto.randomUUID in secure contexts, so on a self-hosted server accessed over plain HTTP (typical LAN/docker setup) the call throws TypeError synchronously 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) and lib/plexAuth.ts (Plex client ID) both carry ad-hoc typeof crypto.randomUUID === "function" fallbacks — which is why everything else works over HTTP and only these two buttons break. ProfileCustomizeHome is unaffected because the server assigns IDs there.

Fix

  • New shared helper web/src/lib/uuid.ts — randomUUID() uses crypto.randomUUID when available and otherwise generates an RFC 4122 v4 UUID via crypto.getRandomValues, which is available in insecure contexts (with a Math.random last resort).
  • Use it in both section-add paths.
  • Replace the two duplicated ad-hoc fallbacks in api/client.ts and lib/plexAuth.ts with the same helper (removes non-UUID-shaped web-…/silo-… fallback IDs; existing stored IDs are untouched). getOrCreateDeviceId can no longer return null, so the dead null-branch in getDeviceHeaders is 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.
  • Targeted vitest run (SectionEditorDrawer, client, settings pages): 46/46 pass.
  • Fallback path exercised in isolation with crypto.randomUUID absent: 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

  • Bug Fixes
    • Improved reliability when generating unique identifiers across supported environments by using a consistent UUID helper.
    • Ensured device metadata consistently includes a device identifier in outgoing requests.
    • Improved identifier creation for saved sections, gallery-derived entries, and Plex client connections.

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]>
@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b5352e50-3a4d-4258-8d7f-2f89eb6f46da

📥 Commits

Reviewing files that changed from the base of the PR and between 82379fa and 0834edc.

📒 Files selected for processing (1)
  • web/src/lib/uuid.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/lib/uuid.ts

📝 Walkthrough

Walkthrough

A shared randomUUID() helper now generates UUID v4 identifiers with runtime fallbacks. Device IDs, Plex client identifiers, and profile section IDs use the helper, and device headers always include the generated device ID.

Changes

UUID Generation Centralization

Layer / File(s) Summary
Shared UUID helper
web/src/lib/uuid.ts
Adds RFC 4122 version 4 UUID generation using crypto.randomUUID(), crypto.getRandomValues(), or Math.random().
API and Plex identifier generation
web/src/api/client.ts, web/src/lib/plexAuth.ts
Uses the shared helper for device and Plex client identifiers, and always constructs device headers with a device ID.
Profile section identifier generation
web/src/components/sections/SectionEditorDrawer.tsx, web/src/pages/settings/HomeScreenSettings.tsx
Uses the shared helper for saved and gallery-derived profile section IDs.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main fix: enabling Add Section on insecure origins by replacing unavailable crypto.randomUUID usage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/section-add-insecure-context

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5d7eec7 and 82379fa.

📒 Files selected for processing (5)
  • web/src/api/client.ts
  • web/src/components/sections/SectionEditorDrawer.tsx
  • web/src/lib/plexAuth.ts
  • web/src/lib/uuid.ts
  • web/src/pages/settings/HomeScreenSettings.tsx

Comment thread web/src/lib/uuid.ts Resolved
Addresses CodeRabbit review on PR #458.

Co-Authored-By: Claude Fable 5 <[email protected]>
@Quick104
Quick104 merged commit 7cfdabb into main Jul 23, 2026
5 checks passed
@Quick104
Quick104 deleted the fix/section-add-insecure-context branch July 23, 2026 16:06
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