Skip to content

Studio: /login shows the sign-in form to a signed-in member, and sign-in forgets the deep link #388

Done

Description

@Madraka

What happens

A signed-in member who opens /login in Studio (for example from a bookmark, the browser history or a typed URL) sees the sign-in form again, with its "Create account" tab. Reproduced on studio.cloudhal.com on 2026-12-02: /api/auth/get-session returns a session, and /login still shows the form.

A related problem: when a signed-out member opens a deep link (such as /sites/<site>/entries/<id>), requireSession redirects to /login without remembering the target. After sign-in, LoginPage always goes to /sites, so the link the member opened is lost.

Why

  • apps/studio/src/router.tsx: loginRoute has no beforeLoad, so nothing checks for a session. Only the protected routes (requireSession) do.
  • requireSession throws redirect({ to: "/login" }) without the target, and LoginPage.submit then calls navigate({ to: "/sites" }).

What it should do

Studio should treat /login as a guest-only route, like most admin consoles and TanStack Router's authenticated-routes example:

  1. Signed in → leave /login. loginRoute.beforeLoad checks the session with cachedSession (no extra request when one is cached) and redirects to the requested target if there is one, otherwise to /sites.

    • Exceptions:
      • An RFC-0044 authorization request (?client_id=…&sig=…) stays on the page, so the provider can still ask for sign-in again when it wants to.
      • A playground has no sign-in (RFC-0036 §5), so it goes to /sites.
    • /forgot-password and /reset-password get the same check. /invite does not: it accepts an invite for the signed-in member too.
  2. Signed out → come back after sign-in. requireSession redirects with search: { redirect: location.href }. loginRoute.validateSearch accepts redirect only if it is a same-origin path, so it cannot become an open redirect:

    • it must start with /;
    • it must not start with // or /\;
    • it must have no scheme;
    • it must be at most 2 kB.

    After sign-in (and after sign-up), LoginPage goes there instead of /sites.

  3. Sign-out still clears the cached session (forgetSession) before going to /login, so the new check never bounces a member who has just signed out.

Tests

  • Router: with a session, /login redirects to /sites.
  • Router: with a session, /login?redirect=/sites/a redirects to /sites/a.
  • Router: with a session, /login?client_id=x&sig=y does not redirect.
  • Router: without a session, a protected deep link redirects to /login?redirect=<path>.
  • redirect validation, which must reject:
    • //evil.example
    • /\evil.example
    • https://evil.example
    • javascript:…
    • a 100k-character value (hard rule 13)
  • LoginPage: after sign-in it goes to the validated redirect.
  • Sign-out followed by /login: the form shows (cache cleared).

Research: remembered and multiple accounts (2026-12-02)

The question: should a signed-out /login offer the last account used (like Cloudflare), or should one browser hold several signed-in accounts with a switcher (like GitHub or Google)?

How others do it

Product What is shown Where it is kept How it is removed
Cloudflare dashboard (changelog 2026-08-21) Opt-in "login profile", offered after sign-in: email, method and which was used last; up to 5 per device; picking one prefills the email or resumes SSO in the browser removed from the list on the login page
GitHub (changelog 2023-11-03, docs) several signed-in accounts and a switcher; switching needs no new sign-in until a session expires browser sessions "Remove" per account, "Sign out from all accounts"
Google (help) account chooser; signed-out accounts stay listed browser "Remove an account", in each browser
Clerk (2025-09-12), Better Auth last-login-method a "last used" badge on the method only (Google, email…) cookie or client state expires (Better Auth: 30 days)

Security rules that apply

  • Opt-in. A remembered email shows who used this browser to anyone who sits down at it next, so it is kept only when the member asks. The login page offers "Not you? Forget" and keeps failed sign-ins generic, so they do not reveal whether an account exists (OWASP Authentication).
  • Not a credential, not in an auth cookie. It holds the email and display name only: never a token, a session id or a role. Session tokens stay in HttpOnly cookies (OWASP Session Management, NIST SP 800-63B-4 §5.1). localStorage is acceptable for this; OWASP's web-storage warning is about tokens.
  • Bounded. At most 5 entries, each forgotten after 30 days without a sign-in, and cleared by "Forget" or by "Sign out and forget". Normal sign-out does not send Clear-Site-Data: "storage", which would wipe it too.
  • Several sessions must be visible and revocable per account. Studio already lists sessions and revokes the others (AccountPage).

Better Auth 1.7

  • multi-session:
    • up to 5 sessions per device;
    • one signed cookie per account, <session>_multi-<token>;
    • endpoints list-device-sessions, set-active and revoke.
    • Sign-out ends every session on the browser, not only the active one.
    • CVE-2025-71402 (unsigned _multi- cookies on sign-out) was fixed in 1.4.0.
  • last-login-method:
    • stores the method only, in a non-HttpOnly cookie, for 30 days;
    • with email and password as the only method, it would always say "email".

Cloudhal's own constraints

  • One organization per deployment (RFC-0005 §11). Two staff accounts in one Studio are rare; a switcher helps mostly someone testing roles.
  • Switching changes the cookie for every tab. Studio keeps the session for 5 minutes (lib/session-cache.ts), and the API caches it in a cookie for 60 s. A second tab would go on showing account A while its writes run as account B: the wrong author in the audit log and the wrong role for the screen. A switcher would need every tab to reload on switch (a BroadcastChannel) and a check that the session cache and the cookie cache follow at once.
  • Field hint. The email field uses autoComplete="email" in sign-in mode. Password managers pair the identifier and password more reliably with username (and later username webauthn).

Proposal

  1. This issue: the guest-only /login and the kept deep link. As described above.
  2. Same PR: field hints. Sign-in uses autoComplete="username"; sign-up keeps email and new-password. The browser's password manager then offers the last used account, and Studio stores nothing.
  3. Follow-up: opt-in remembered accounts, like Cloudflare.
    • After a sign-in, a "Remember this account on this device" choice. It is off by default and never shown in a playground.
    • Up to 5 entries in localStorage. Each holds the email, the display name and the last-used time; no avatar request, no token.
    • The signed-out /login lists them. Picking one prefills the email and focuses the password field.
    • Each entry has "Forget", and the user menu adds "Sign out and forget".
    • Entries expire after 30 days unused, and each Studio origin keeps its own.
    • All copy goes through useT() in every language.
  4. Later, with an RFC: passkeys with autofill (Better Auth passkey, signIn.passkey({ autoFill: true })). This is the modern form of "last used account": the browser offers the account, and there is no password to type. It needs new tables, so it is a contract change. last-login-method becomes useful then.
  5. Deferred: several signed-in accounts (multi-session). Revisit when one Studio serves several organizations (the hosted Cloud). That work needs the reload across tabs, per-account Remove next to "Sign out of all accounts", and an audit review.

🤖 Generated with Claude Code

Activity

  1. added
    bug
    enhancement
    on Dec 2, 2026
  2. added 3 commits that reference this issue on Dec 2, 2026
  3. Madraka commented on Dec 3, 2026

    @Madraka
    ContributorAuthor

    Done for this issue's scope, shipped in 0.12.0:

    Proposal steps 4 (passkeys, which needs an RFC) and 5 (multi-session, deferred) move to 395.

  4. Madraka commented on Dec 3, 2026

    @Madraka
    ContributorAuthor

    Follow-up issue: #395

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions