fix(web): avoid crypto.randomUUID under non-secure-context deployments - #205
fix(web): avoid crypto.randomUUID under non-secure-context deployments#205ZerxLabBot wants to merge 1 commit into
Conversation
cloudDeviceId() in web/src/lib/cloud/session.ts called crypto.randomUUID() unconditionally. Per the WHATWG Secure Contexts spec, randomUUID() is only exposed on secure origins (HTTPS, or http://localhost); getRandomValues() carries no such restriction. The headless server (ghcr.io/zerx-lab/fluxdown-server) binds 0.0.0.0:17800 with no built-in TLS, so a typical NAS/Docker deployment reached over plain http://<lan-ip> is a non-secure origin, and login threw immediately (cloudDeviceId() runs on every FluxCloud login request via lib/cloud/client.ts's deviceInfo()). Replace crypto.randomUUID() with a local RFC 4122 v4 UUID generator built on crypto.getRandomValues(), matching the existing getRandomValues-based pattern already used in components/settings/SecuritySettings.tsx. Fixes #204
review |
|
PR is ready for review as-is — CLA signed, typecheck/lint clean, no outstanding changes requested. |
|
@ZerxLabBot #179 也是同样问题,检查同类问题一起关闭 |
|
Confirmed: #179 is the same bug ( #179 should be closed as duplicate of #204 once #205 merges. |
Repro
Self-hosted
ghcr.io/zerx-lab/fluxdown-serverdeployed via Docker on a NAS (飞牛OS) and reached over plainhttp://<lan-ip>:17800(no TLS in front). Logging into the FluxCloud panel throwscrypto.randomUUID is not a function. (In 'crypto.randomUUID()', 'crypto.randomUUID' is undefined). Reproduced by transcribingcloudDeviceId()verbatim and invoking it against acryptoshim exposing onlygetRandomValues(norandomUUID) — exactly how Chromium/WebKit exposewindow.cryptoon a non-secure origin per the WHATWG Secure Contexts spec (https://developer.mozilla.org/docs/Web/API/Crypto/randomUUID: "available only in secure contexts"). Output matched the reporter's pasted error text verbatim.Cause
web/src/lib/cloud/session.ts'scloudDeviceId()calledcrypto.randomUUID()unconditionally to mint the panel's persistent FluxCloud device id.randomUUID()is spec-restricted to secure contexts (HTTPS, orhttp://localhost); the headless server binds0.0.0.0:17800with no built-in TLS, so a typical NAS/Docker deployment reached over plain LAN-IP HTTP is a non-secure origin and the method is simply absent onwindow.crypto.cloudDeviceId()runs on every FluxCloud login request (lib/cloud/client.ts'sdeviceInfo()), so login failed immediately.Fix
randomUuidV4()inweb/src/lib/cloud/session.tsthat builds an RFC 4122 v4 UUID fromcrypto.getRandomValues()(setting the version/variant bits per spec) —getRandomValues()carries no secure-context restriction, and is already the pattern used forcomponents/settings/SecuritySettings.tsx's token generation.cloudDeviceId()'scrypto.randomUUID()call forrandomUuidV4().Verification
bun x tsc -b --noEmit(web) — clean, no errors.bun run lint— unchanged pre-existing warnings only,session.tsnot flagged. Ran 10,000 iterations of the new generator against both an insecure-contextcryptoshim (norandomUUID, matching the reported deployment) and the real environmentcryptoobject: all outputs match the RFC 4122 v4 pattern (^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$) with zero collisions, and no exception is thrown under the insecure-context shim (previously threwTypeError: crypto.randomUUID is not a function, matching the report verbatim).Fixes #204