fix: import randomUUID from node:crypto for non-secure contexts#3574
fix: import randomUUID from node:crypto for non-secure contexts#3574guoyangzhen wants to merge 16 commits intosimstudioai:mainfrom
Conversation
The normalizeFileInput helper only handles file objects from the upload UI, not plain URL strings. When users pass a URL in advanced mode (e.g., <Block.result.photo> resolving to 'https://example.com/image.jpg'), normalizeFileInput tries to JSON.parse it, fails, returns undefined, and throws 'Photo is required.' Fix: check if the param is a plain string first (URL or file_id) and pass it through directly before attempting file normalization. Applies to: telegram_send_photo, telegram_send_video, telegram_send_audio, telegram_send_animation. Fixes simstudioai#3220
crypto.randomUUID() is only available in secure contexts (HTTPS). When accessing self-hosted sim over HTTP (e.g., http://192.168.x.x), the global crypto API doesn't expose randomUUID, causing white screen. Fix: import { randomUUID } from node:crypto instead of relying on the global crypto.randomUUID(). Affected files: - tools/langsmith/utils.ts: runId fallback - executor/handlers/workflow/workflow-handler.ts: instanceId generation Fixes simstudioai#3393
PR SummaryMedium Risk Overview Updates a few server-side callsites to use Written by Cursor Bugbot for commit 608a0a4. This will update automatically on new commits. Configure here. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile SummaryThis PR fixes a Key changes:
Notable concern:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Browser as Browser (HTTP)
participant WFHandler as WorkflowBlockHandler
participant NodeCrypto as node:crypto
participant WebCrypto as globalThis.crypto
Note over Browser, WebCrypto: Before fix — HTTP context
Browser->>WFHandler: Execute workflow block
WFHandler->>WebCrypto: crypto.randomUUID()
WebCrypto-->>WFHandler: ❌ TypeError (not a function in non-secure context)
Note over Browser, NodeCrypto: After fix — HTTP context
Browser->>WFHandler: Execute workflow block
WFHandler->>NodeCrypto: randomUUID() (polyfilled by webpack)
NodeCrypto-->>WFHandler: ✅ "550e8400-e29b-41d4-..."
WFHandler-->>Browser: instanceId assigned, execution proceeds
Last reviewed commit: 40250a2 |
| @@ -1,3 +1,4 @@ | |||
| import { randomUUID } from 'node:crypto' | |||
There was a problem hiding this comment.
Incomplete fix — many other call sites affected
The same crypto.randomUUID() pattern exists in many other files that also run in a non-secure (HTTP) context and will throw the same error. This PR only patches two files, but a broad search reveals ~100+ additional occurrences across client-side code, including:
apps/sim/hooks/use-undo-redo.ts(multiple calls — client-side hook)apps/sim/hooks/use-collaborative-workflow.ts(client-side hook)apps/sim/stores/notifications/store.ts,stores/chat/store.ts,stores/workflows/workflow/store.ts, etc. (all Zustand stores run in the browser)apps/sim/app/workspace/**/components/**/*.tsx(various client-side React components)apps/sim/socket/handlers/operations.ts(socket handler, called from client context)apps/sim/lib/copilot/client-sse/content-blocks.ts(client-side SSE utility)
All of these will still throw TypeError: crypto.randomUUID is not a function on HTTP deployments. The fix should be extended consistently to all files, or at minimum the client-side ones that will fail in a non-secure browser context.
Comprehensive fix for HTTP deployments (non-secure contexts). crypto.randomUUID() only works in HTTPS contexts. In HTTP deployments (e.g., http://192.168.x.x:3000), it throws TypeError causing white screen. Changes: - Add shared generateId() utility in lib/utils/uuid.ts with automatic fallback: crypto.randomUUID() → getRandomValues → Math.random - Replace all 38 client-side crypto.randomUUID() calls with generateId() across hooks/, stores/, app/chat/, app/workspace/, serializer/, triggers/ - Server-side code (app/api/, lib/auth/, lib/billing/) unchanged - Node.js always has crypto.randomUUID() available Fixes simstudioai#3393
8a65db0 to
e38b27b
Compare
…onents Fixes the import ordering issue flagged by Cursor Bugbot review. In Next.js, 'use client' must be the very first statement. The previous commit placed generateId imports before 'use client' in 15 component files. Also addresses Greptile feedback about comprehensive coverage: - All 38+ client-side files now use generateId() utility - Server-side files continue using crypto.randomUUID() directly - Shared utility provides automatic fallback for non-secure contexts Fixes simstudioai#3393
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Problem
When accessing self-hosted sim over HTTP (e.g.,
http://192.168.x.x:3000), the app shows a white screen withTypeError: crypto.randomUUID is not a function.Fix
New shared utility
lib/utils/uuid.tswithgenerateId()providing automatic fallback:crypto.randomUUID()— Node.js + HTTPS browserscrypto.getRandomValues()— HTTP browsersMath.random()— last resortComprehensive replacement: All 38 client-side files use
generateId(). Server-side code unchanged.Fixes #3393