Web UI - attaching images over HTTP (non-secure context) does not work #8988

Open
opened 2026-02-16 18:11:20 -05:00 by yindo · 0 comments
Owner

Originally created by @selimerunkut on GitHub (Feb 10, 2026).

Originally assigned to: @adamdotdevin on GitHub.

Bug Description

crypto.randomUUID() throws a DOMException when called in a non-secure browser context (plain HTTP, not HTTPS). This crashes the web UI when attaching images and in other spots that generate IDs.

Error

Uncaught TypeError: crypto.randomUUID is not a function

Root Cause

The existing code uses optional chaining:

id: crypto.randomUUID?.() ?? Math.random().toString(16).slice(2)

However, optional chaining doesn't help here — the randomUUID method exists on the crypto object, but it throws when the browser context isn't secure (e.g., accessing via HTTP instead of HTTPS, or in certain embedded contexts).

Affected Files

  • packages/app/src/components/prompt-input/attachments.ts — image attachment crash
  • packages/app/src/context/comments.tsx
  • packages/app/src/utils/perf.ts

Expected Behavior

The web UI should gracefully fall back to Math.random().toString(16).slice(2) when crypto.randomUUID() is unavailable or throws.

Environment

  • Accessing OpenCode web interface over HTTP (non-HTTPS)
  • Browser: Any modern browser in non-secure context

Additional Context

Server-side usages in packages/opencode and packages/enterprise are unaffected since Node/Bun always runs in a secure context.

Originally created by @selimerunkut on GitHub (Feb 10, 2026). Originally assigned to: @adamdotdevin on GitHub. ## Bug Description `crypto.randomUUID()` throws a `DOMException` when called in a non-secure browser context (plain HTTP, not HTTPS). This crashes the web UI when attaching images and in other spots that generate IDs. ## Error ``` Uncaught TypeError: crypto.randomUUID is not a function ``` ## Root Cause The existing code uses optional chaining: ```typescript id: crypto.randomUUID?.() ?? Math.random().toString(16).slice(2) ``` However, optional chaining doesn't help here — the `randomUUID` method *exists* on the `crypto` object, but it *throws* when the browser context isn't secure (e.g., accessing via HTTP instead of HTTPS, or in certain embedded contexts). ## Affected Files - `packages/app/src/components/prompt-input/attachments.ts` — image attachment crash - `packages/app/src/context/comments.tsx` - `packages/app/src/utils/perf.ts` ## Expected Behavior The web UI should gracefully fall back to `Math.random().toString(16).slice(2)` when `crypto.randomUUID()` is unavailable or throws. ## Environment - Accessing OpenCode web interface over HTTP (non-HTTPS) - Browser: Any modern browser in non-secure context ## Additional Context Server-side usages in `packages/opencode` and `packages/enterprise` are unaffected since Node/Bun always runs in a secure context.
yindo added the web label 2026-02-16 18:11:20 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8988