[Bug] Web UI falls back to the onboarding wizard when RPC authentication fails, instead of reporting an authentication error

Author: tanyaotingCreated Sep 27, 2026Updated Sep 27, 2026

Summary

Opening http://127.0.0.1:3458/ without a valid ccr_web_token renders the "Get Started" onboarding wizard, claiming CCR has never been configured — even though the configuration is fully intact. The UI has no "authentication failed" state at all.

Because the onboarding wizard can save configuration, this is not only misleading but potentially destructive: a user who follows it may overwrite their existing providers and Router rules.

Environment

  • CCR @musistudio/claude-code-router 3.1.1 (npm CLI, macOS, arm64)
  • Reproduced against main @ f2e01bfe0c01
  • GET http://127.0.0.1:3458/ → 200
  • POST http://127.0.0.1:3458/api/ccr/rpc without x-ccr-web-auth → {"ok":false,"error":{"message":"CCR web authentication token is missing or invalid."}}

Steps to reproduce

  1. Start the service: ccr ui → open the printed URL (which contains ?ccr_web_token=…). Note that the page loads and shows the configured state, e.g. an existing provider under Providers.

  2. Open a new browser tab and navigate to http://127.0.0.1:3458/ — i.e. the bare URL, with no token.

  3. The static page returns 200 and the UI loads, but it shows the onboarding wizard, as if CCR had never been configured.

  4. Verification that the configuration was never lost — with the correct token:

    • getOnboardingFinished → true
    • getConfig → returns the full configuration, including the existing provider and Router rules

Root cause

The web client keeps the management token in sessionStorage (ccr.webAuthToken), populated only from the ccr_web_token query parameter on first load, and then removed from the address bar via history.replaceState. The static GET / handler does not validate the token, so the page itself always loads. Consequently, in any tab that was not opened with the token in the URL, every RPC call fails with the 401 above — and the UI silently treats that as "not configured".

packages/ui/src/pages/home/App.tsx (main @ f2e01bfe0c01):

typescript
// L183 — the initial view is already "onboarding"
const [activeView, setActiveView] = useState<ViewId>("onboarding");

// L345-348
void window.ccr.getProviderPresets()
  .then(setProviderPresets)
  .catch(() => setProviderPresets([]))                 // degrades to an empty list
  .finally(() => setProviderPresetsLoaded(true));

// L349-354
void window.ccr.getConfig()
  .then(syncConfigState)
  .catch(() => {
    // Fall back to the bundled defaults; the rest of the UI can still render.
  })                                                   // silently falls back to bundled defaults
  .finally(() => setConfigLoaded(true));

// L355-362
void window.ccr.getOnboardingFinished()
  .then((finished) => {
    setOnboardingFinished(finished);
    setOnboardingProfileConfirmed(finished);
    setActiveView(finished ? "overview" : "onboarding");
  })
  .catch(() => setActiveView("onboarding"))            // <-- auth failure treated as "never onboarded"
  .finally(() => setOnboardingStatusLoaded(true));

All three startup calls swallow their errors, so nothing surfaces to the user. The .catch() on L361 conflates two very different conditions — "the server says onboarding is not finished" and "I am not authorised to ask" — and routes both to the onboarding wizard. Line 361 in this source is identical to the published 3.1.1 bundle (assets/main.js), so released builds are affected too.

Impact

Potentially destructive. If the user completes the wizard and saves, the frontend sends a whole-config saveConfig. Since getConfig failed silently, the UI is holding the bundled defaults rather than the user's data — so saving replaces app_config.default and can wipe existing providers and Router rules.

This interacts with #1826 (saveAppConfig does a blind whole-blob replace with no read-modify-write), which makes the overwrite unrecoverable from the UI side.

Suggested fix

Distinguish authentication/transport failures from "not onboarded":

  • On a 401 from any RPC, render a dedicated authentication error view that tells the user to open the full URL containing ?ccr_web_token=… (or to run ccr ui), and do not enter the onboarding wizard.
  • Avoid defaulting activeView to "onboarding" before getOnboardingFinished has resolved successfully; a loading state would prevent the flash of a misleading wizard.
  • Consider also validating the token on GET / so a bare URL does not silently serve an unusable UI.

Note that surfacing errors is already the intent elsewhere: packages/ui/src/web-client-bridge.ts produces a readable message for 404 — "CCR management service is unavailable. Make sure the CCR app or ccr ui command is running, then retry." — the 401 path simply isn't handled.

Source: musistudio/claude-code-router