t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: Desktop initializes Clerk on startup even when Managed Policy sets limits.connect: false

Open nabertronic opened this issue 4 days ago • 0 comments

Before submitting

  • [x] I searched existing issues and did not find a duplicate (distinct from host-side policy enforcement in #27197 and #26967).
  • [x] I included enough detail to reproduce or investigate the problem.

Area

apps/desktop

Steps to reproduce

  1. Deploy a Managed Policy with "limits": { "connect": false } (and optionally "telemetry": false) and confirm with t3 policy show.
  2. Launch a release build of the T3 Code Desktop app on a fresh, signed-out profile (never signed in to T3 Connect).
  3. Observe Desktop main-process initialization and renderer startup.

Expected behavior

When Managed Policy disables T3 Connect (limits.connect: false), the Desktop app should not initialize Clerk or contact Clerk's Frontend API on startup. (More broadly, for local-only desktop users who have not signed in to T3 Connect, Clerk should only initialize lazily when Connect sign-in is initiated.)

Actual behavior

While the server enforces limits.connect: false for host linking, proofs, and credentials (apps/server/src/cloud/CloudLink.ts:1690-1720), Desktop still initializes Clerk unconditionally at startup:

  • Electron main process calls clerk.configure during startup without consulting DesktopManagedPolicy (apps/desktop/src/app/DesktopApp.ts:418, apps/desktop/src/app/DesktopClerk.ts:88-107).
  • In the renderer, apps/web/src/cloud/publicConfig.ts:97-110 returns hasCloudPublicConfig() === true whenever window.desktopBridge !== undefined and build-time Clerk/relay env vars are present, so apps/web/src/main.tsx:25-48 immediately mounts ElectronManagedAuthShell (<ClerkProvider>) before the renderer receives serverConfigs / managedPolicy.
  • (Similarly on mobile, apps/mobile/src/features/cloud/CloudAuthProvider.tsx:8-30 initializes the Clerk singleton at module load whenever a publishable key and relay URL are present.)

DesktopManagedPolicy is already read in apps/desktop/src/backend/DesktopServerExposure.ts:489 and apps/desktop/src/ipc/methods/window.ts:107, so gating clerk.configure and exposing a getConnectEnabled() flag on desktopBridge (mirroring getRelayTelemetryEnabled()) would cleanly prevent Clerk initialization when connect: false is set.

Impact

Minor bug or occasional failure

Version or commit

main @ 6696eefe2

Environment

Source review against main @ 6696eefe2 (macOS / Electron desktop build with cloud public config).

Workaround

Build from source without VITE_CLERK_PUBLISHABLE_KEY / VITE_T3CODE_RELAY_URL, or block clerk.t3.codes at the host firewall.

nabertronic avatar Nov 27 '26 20:11 nabertronic