devtools icon indicating copy to clipboard operation
devtools copied to clipboard

Disabling client auth (clientAuth:false / VITE_DEVTOOLS_DISABLE_CLIENT_AUTH) no longer trusts the client in 0.5

Open antfubot opened this issue 3 months ago • 0 comments

Describe the bug

Disabling client auth no longer marks the client's RPC session as trusted. Whether via the VITE_DEVTOOLS_DISABLE_CLIENT_AUTH=true env var or devtools: { clientAuth: false }, the DevTools client connects and receives the dock list, but __DEVFRAME_HUB_CLIENT_CONTEXT__.rpc.isTrusted stays false and the connection status stays unauthorized. As a result the client keeps showing the authorization prompt and the embedded client never mounts — so headless/e2e environments that relied on this flag to bypass the interactive OTP prompt can no longer drive DevTools.

This is a regression in @vitejs/[email protected] (with [email protected] / @devframes/[email protected]). Downstream, it breaks the Nuxt DevTools e2e suite (every DevTools-dependent test hangs waiting for the client to become trusted).

Root cause

authDisabled is computed and applied only to the transport hub, but the context RPC always registers the interactive-auth handler, so the auto-trust shim is never in effect.

  1. createDevToolsContext() unconditionally registers the interactive-auth RPC functions on the context RPC — regardless of clientAuth / the env var:

    // @vitejs/devtools/dist/server-BML20xMb.js:270
    const rpcHost = context.rpc;
    for (const fn of getAuthHandler(context).rpcFunctions) rpcHost.register(fn);
    

    getAuthHandler is always the interactive OTP handler (createInteractiveAuth), whose anonymous:devframe:auth only trusts a session when a valid static/OTP token is presented.

  2. authDisabled is computed later, in createDevToolsHub(), and is only passed to initHub({ auth }) (the transport shell) — never to the context RPC:

    // @vitejs/devtools/dist/server-Bf9AYuOm.js:52,60
    const authDisabled = context.mode === "build"
      || context.viteConfig.devtools?.config?.clientAuth === false
      || process.env.VITE_DEVTOOLS_DISABLE_CLIENT_AUTH === "true";
    // ...
    auth: authDisabled ? false : getAuthHandler(context),
    
  3. devframe's auth: false auto-trust shim only registers when anonymous:devframe:auth is not already defined — but step 1 already registered it, so the shim is skipped:

    // devframe/dist/rpc-core-*.mjs:52
    if (options.auth === false && !rpcHost.definitions.has("anonymous:devframe:auth"))
      rpcHost.register({ name: "anonymous:devframe:auth", handler: () => { /* mark session trusted */ return { isTrusted: true } } });
    

Net effect: disabling auth removes the transport/OTP gate, but the context RPC still has the interactive-auth handler and never marks the session trusted, so isTrusted stays false and the client UI never mounts.

Reproduction

  1. Any Vite app using @vitejs/[email protected].

  2. Start the dev server with VITE_DEVTOOLS_DISABLE_CLIENT_AUTH=true (or set devtools: { clientAuth: false }).

  3. In the app page console:

    const ctx = window.__DEVFRAME_HUB_CLIENT_CONTEXT__
    ctx.connection.status      // 'unauthorized'
    ctx.rpc.isTrusted          // false
    await ctx.rpc.requestTrust() // false  (hits the interactive gate; no valid token)
    

The DevTools UI shows the authorization prompt instead of mounting, despite auth being "disabled".

Expected: with auth disabled, the client session should be trusted automatically (isTrusted === true, status connected) and the UI should mount without a prompt.

Suggested fix

When auth is disabled, either:

  • have createDevToolsContext() skip registering the interactive-auth handler (so devframe's auth: false auto-trust shim can register and trust sessions), or
  • mark incoming sessions isTrusted at connect time when authDisabled, or
  • surface the auth-disabled state in the connection meta so the client auto-trusts.

The decision that today only feeds initHub's transport auth needs to also reach the context RPC's trust gate.

System Info

  • @vitejs/devtools: 0.5.0
  • @vitejs/devtools-kit: 0.5.0
  • devframe: 0.9.2
  • @devframes/hub: 0.9.2
  • Vite: 8.x
  • Observed via Nuxt DevTools v4 (embeds @vitejs/devtools) e2e suite.

antfubot avatar Aug 20 '26 03:08 antfubot