Skip to content

fix(gateway): harden the SSO login in the TUI and desktop app - #357

Merged
quickbeard merged 1 commit into
mainfrom
sso-login-fixes
Sep 10, 2026
Merged

quickbeard merged 1 commit into
mainfrom
sso-login-fixes

Conversation

@quickbeard

Copy link
Copy Markdown
Owner

Summary

Three fixes from an investigation of the SSO sign-in flow shared by the TUI and the desktop app.

  1. Loopback callback server crash (confirmed). The /callback listener in packages/codev-gateway/src/sso.ts built the request URL from the Host header. A malformed value such as Host: [ threw inside the request listener, which is an uncaught exception, and took down the whole process (the TUI, or the Electron main process) during the up-to-five-minute sign-in wait. Any local process can reach the port. The URL is now parsed against a fixed http://127.0.0.1 base with URL.parse, and a target the parser still rejects gets a 400. Regression test added.
  2. TUI quit the app on any SSO failure. Both catch blocks in the configure dialog exited the process, which is right for the first-run gate but not for the startup key re-check or /configure on a working install, where a five-minute login timeout or one failed token exchange killed a session the user was in. The helper now checks whether a provider is connected: quit with the epilogue only when unconfigured, otherwise show the reason as a toast and close the dialog. /configure also opens dismissable on a configured install, like the desktop app's "Get a new API Key".
  3. Desktop nagged non-gateway users every launch. The startup key check opened the configure dialog for both needs-login reasons, and the Custom/Connect provider paths never write the shared auth file, so an Anthropic or custom-key user saw the dialog on each launch. The reason now travels over IPC and the gate prompts for a rejected key only, matching the TUI.

Divergences and docs

  • DIVERGENCES.md: updated the packages/tui/src/app.tsx row for the dismissable /configure dialog. Every other touched file is fork-only.
  • CHANGELOG.md: three entries under Gateway.

Test plan

  • bun test in packages/codev-gateway (78 pass, including the new malformed-Host test)
  • bun test src/main/gateway-sso in packages/desktop (23 pass, no-key and rejected reasons asserted)
  • bun test test/configure-gate.test.ts in packages/tui
  • bun typecheck in packages/codev-gateway, packages/tui, packages/app, packages/desktop
  • Manual: TUI /configure on a configured install, press Escape, then trigger a login failure and confirm the app stays up
  • Manual: desktop configured via Connect provider only, relaunch, confirm no configure dialog

🤖 Generated with Claude Code

https://claude.ai/code/session_01KUxGp8Cs7mMifGyDDWf57b

Three fixes from an investigation of the SSO sign-in flow:

- The loopback callback server parsed the request URL against the Host
  header. A malformed Host (any local process can send one) threw inside the
  request listener, an uncaught exception that took down the TUI or the
  desktop main process for the length of the sign-in wait. Parse against a
  fixed 127.0.0.1 base and answer 400 for a target the parser still rejects.
- The TUI configure flow quit the whole app on any SSO failure, even from
  the startup key re-check or /configure on a working install. Quit only on
  the first-run gate; with a provider connected, toast the reason and close
  the dialog. /configure opens dismissable on a configured install.
- The desktop startup key check prompted for a missing gateway key as well
  as a rejected one, so every Custom/Connect provider user saw the configure
  dialog on each launch. Carry the needs-login reason over IPC and prompt
  for a rejected key only, matching the TUI.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KUxGp8Cs7mMifGyDDWf57b
@quickbeard
quickbeard merged commit fa8e638 into main Sep 10, 2026
0 of 5 checks passed
@quickbeard
quickbeard deleted the sso-login-fixes branch September 10, 2026 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant