Skip to content

A dashboard sign-in link asks before switching accounts unless this tab started the sign-in - #320

Merged
zlareb1 merged 15 commits into
mainfrom
sec/dashboard-link-token-confirm
Nov 7, 2026
Merged

zlareb1 merged 15 commits into
mainfrom
sec/dashboard-link-token-confirm

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

A dashboard link carrying #token= signs the browser in without asking only when it answers the SSO sign-in this tab started, or when the token is for the account already signed in; any other link asks first, naming the account it signs in as.

Why

The dashboard took a #token=<jwt> fragment on any page and stored it, replacing whatever token the browser held, with nothing tying it to a sign-in this browser started. Anyone holding a valid token on the deployment (an org member, or anyone where self-signup is open) could send a link that silently signed the reader into the sender's account, so what the reader then did (documents uploaded, memories written, agent tokens minted on Setup) landed in the sender's namespace, every open tab following. The SSO round trip itself is bound to the browser by a sealed state cookie; the hand-off of the token to the dashboard after it was not.

Design

  • The sign-in gate starts SSO with a random nonce it keeps in the tab's session storage (loom_sign_in_pending_v1, {nonce, at}): /oauth/sso?n=<nonce>, from the button's plain click and from the automatic resume after an expired session. A click that opens another tab or window follows the bare link and writes no mark.
  • /oauth/sso seals a well-formed nonce (16 to 64 url-safe characters) into the sign-in record its cookie already carries. The callback lands the token at /me?n=<nonce>#token=<jwt>, checking the nonce again before it goes in the URL; a missing or malformed one is neither sealed nor echoed.
  • Boot reads n from the landing's query and scrubs it with the token. It stores the token without asking when n matches the tab's nonce, which is used up on every boot and lasts ten minutes. A token is also stored without asking when whoami, asked with that token in its own Authorization header (and asked again while a replica answers 503, as boot does), accepts it and answers with the subject and org of the token held; the link token's own claims are unverified and never decide: until then nothing is written, so a refused or unanswered one leaves the held token in place and no other tab hears of it.
  • Any other token is first asked about with whoami, with its own header and the same 503 retry; one the server refuses, or that goes unanswered, is dropped without asking, with nothing stored and no other tab told; when nothing else is signed in, the gate says the link's token was refused. One it accepts stays in memory only, behind a screen that names the account the server says it signs in as and the account the browser holds, as text: Sign in as (Sign in for a token with no subject) stores it, and boot asks whoami again, since the token may have expired while the person read the screen; Cancel drops it and boot goes on with the stored token or the sign-in gate. The screen names the account held when it was put; when another tab stores a different token while it is up, the answer is not taken and the question is put again, naming that account. Whitespace is stripped from a link's token once, so whoami is asked about the token that is stored.
  • A restart from the landing (/me, where Start again leads) keeps the start page the first sign-in saved, so the return goes there.
  • /me?sign_in=sso asks the gate to start SSO with a nonce of that tab's own. Boot takes the ask from the address next to the link token, signed in or not, and passes it to the gate, which starts once for it, only when a Loom page sent the browser there. The dashboard page's boot snippet carries __LOOM_OWN_ORIGIN, true when the load's Sec-Fetch-Site is same-origin (or, without that header, when the Referer has Loom's public origin, default ports included); an ask from another site, or typed, is scrubbed and starts nothing, so no other site can start a sign-in whose token the tab stores unasked. A counted ask always follows a click on a Loom page, so it skips the five-minute guard that keeps the automatic resume after an expired session from looping. The session-ended card's Sign in in a new tab opens it, so that sign-in is stored without asking and the first tab picks it up as before; so does the server's Start again link when it could not finish a dashboard sign-in.
  • Behind a proxy that adds Authorization, or with auth off, the page sends no token of its own: a #token= link is scrubbed and dropped without asking.
  • The dashboard page sends Cross-Origin-Opener-Policy: same-origin, so a page of another origin that opened it keeps no handle to navigate it while it is away at the identity provider. The dashboard opens no popup it needs a handle to: its one window.open (the session-ended card's new tab) is same-origin with noopener, external links carry rel="noreferrer", and SSO is a full-page navigation.

Scope and risk

server/auth/oauth.py (the SSO start, the dashboard landing and its restart link), server/identity/app/dashboard_routes.py (COOP), frontend/src/lib/boot.ts, frontend/src/lib/navigation.ts, frontend/src/api.ts (whoami can ask about a token not yet stored), frontend/src/flows/TokenGate.tsx, frontend/src/components/SessionExpiredBar.tsx, frontend/src/App.tsx, their tests, docs/features/dashboard.md and docs/architecture/security.md. An SSO sign-in started outside the gate (typing /oauth/sso, a modified click on the button) carries no nonce, so its token asks to be confirmed unless it is for the account already signed in. The documented <server>/me#token=<jwt> flow for a minted token takes one confirmation click.

Compatibility, rollout and rollback

  • Wire: /oauth/sso takes an optional ?n=; the dashboard SSO landing is /me?n=<nonce>#token=<jwt> when the start carried one, else /me#token=<jwt> as before; the dashboard page gains Cross-Origin-Opener-Policy: same-origin; the Start again link of a dashboard sign-in the server could not finish points at /me?sign_in=sso; the boot snippet gains window.__LOOM_OWN_ORIGIN.
  • Mixed builds during a rolling upgrade:
    • A sign-in an old dashboard tab started carries no mark and no n, so the new /me page that receives it asks to confirm the account, unless it is the account already signed in.
    • An old dashboard landing at /me?n=<nonce>#token=<jwt> reads the fragment as the token and signs in, but leaves ?n= in the address bar and does not return to the page the sign-in started on.
    • A new dashboard behind an old server gets no n back, so its SSO sign-ins ask to confirm unless they are for the account already signed in.
    • An old dashboard served /me?sign_in=sso by the Start again link ignores the query and shows its SSO button.
    • A sign-in cookie written by either build is read by the other (tab_nonce is optional).
  • Operator steps: none.
  • Rollback: revert.

Tests

  • tests/unit/test_oidc_hardening.py: a well-formed nonce is sealed with the sign-in; missing or malformed ones are not; the landing carries the sealed nonce in the query with the fragment the token alone, and no query when there is no nonce or the sealed one is not well formed; a dashboard sign-in restarts at /me?sign_in=sso. tests/unit/test_dashboard_routes.py: the dashboard page sends COOP, and its own-origin flag is true for a same-origin Sec-Fetch-Site or, without one, an own-origin Referer, and false for cross-site, same-site, none, a foreign or look-alike Referer, and no headers; a Referer without the default port matches a public URL that names it.
  • frontend/src/App.boot.test.tsx: a link with no pending sign-in is not stored and shows the confirmation; confirming stores it; the screen names the subject and org whoami answered, not the token's claims; a link whose claims name the held account but whose whoami answer names another asks; a confirmed token is asked about again, and one refused then shows the refused gate; a refused link with no mark and no held token shows the refused gate; cancelling keeps the previous token and stores nothing; a token the server refuses is dropped without the screen; the landing from this tab's sign-in is stored silently and its query scrubbed; a fresh mark with no nonce or another nonce asks; a mark older than ten minutes counts as none; the same account is asked about with its own header before anything is stored, asked again after a 503 (also when another tab clears the stored token during the wait, since a link token's retry ignores the stored one), stored once whoami accepts it and not asked a second time by boot, while a refused or unanswered one leaves the held token stored and writes nothing; the screen names the held account as text; a token with %20%0A in it is asked about and stored without the whitespace; another tab storing a token while the screen is up puts the question again, naming that account; the session-ended card opens /me?sign_in=sso; a signed-out boot there starts this tab's own sign-in once, one another site sent starts nothing and shows the SSO button, and a signed-in boot drops the ask from the address. frontend/src/lib/boot.test.ts also covers takeSsoAsk: it counts only with __LOOM_OWN_ORIGIN true and scrubs the ask either way. frontend/src/App.linkModes.test.tsx: behind a proxy and with auth off a link's token is dropped unasked and scrubbed.
  • frontend/src/lib/boot.test.ts: the nonce helpers, reading n from the landing's query, and sameAccount comparing the server's answer with the held token. frontend/src/flows/TokenGate.test.tsx: both SSO starts carry the stored nonce, ?sign_in=sso starts one and is scrubbed, also while the resume guard is set, after a sign-out and once only, a modified click follows the bare link and writes no mark, a restart from /me keeps the saved start page, and the confirmation passes axe with and without a subject.
  • npm --prefix frontend test (1,951 tests), npm --prefix frontend run build, Biome, ruff and mypy on the touched server files pass.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. I verified the defect by reading the code path and read the diff and its tests.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

zlareb1 and others added 15 commits November 6, 2026 22:51
…fore it signs in

A dashboard link carrying #token=<jwt> was stored on any page, replacing the
browser's session without a prompt, so anyone holding a valid token could
sign a victim's dashboard into their own account (login CSRF): uploads,
memories and minted agent tokens then landed in the sender's namespace.

The sign-in gate now marks in session storage when this tab starts an SSO
sign-in. Boot takes the mark with the link token and stores the token without
asking only when the mark is under ten minutes old, or when the token names
the same subject and org as the one held. Any other link token is held in
memory only, behind a screen naming its subject and org: "Sign in as
<subject>" stores it, "Cancel" drops it and keeps the browser's session.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ashboard opts out of cross-origin openers

A fresh sign-in mark trusted any token that reached the tab while it was away
at the identity provider: a page that opened the dashboard could navigate it
to /me#token=<its own> after the tab left for /oauth/sso.

The sign-in gate now writes a random nonce to session storage and starts
/oauth/sso?n=<nonce> on every path (the button, the automatic resume). The
server seals a well-formed nonce into the sign-in record its cookie carries
and returns it as /me#token=<jwt>&n=<nonce>; a missing or malformed one is
neither sealed nor echoed. Boot stores a link token without asking only
when its nonce matches the one this tab kept (used up once), or when it
names the account already held. A same-account token the server refuses
gives the held token back instead of signing the person out. The
confirmation screen also names the account the browser is signed in as.

The dashboard page sends Cross-Origin-Opener-Policy: same-origin, so no
other origin's window keeps a handle on it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…-ended card's new tab marks its own sign-in

The nonce now comes back as /me?n=<nonce>#token=<jwt>, so a dashboard that
predates it still reads the fragment as the token alone; the new dashboard
reads n from the query and scrubs it with the token.

The session-ended card's "Sign in in a new tab" opens /me?sign_in=sso, whose
gate scrubs the ask and starts SSO with a nonce of that tab's own, so the
returning token is stored without the confirmation screen.

The confirmation offers a plain "Sign in" for a token without a subject, and
passes axe. docs/architecture/security.md describes the tab binding of the
hand-off and COOP.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The dashboard asks whoami about a same-account link's token with that token
in its own Authorization header before writing anything. A refused or
unanswered one leaves the held token in storage, so nothing has to be put
back and no other tab hears of a token the server did not accept.

docs/architecture/security.md keeps the separate-host rule for the MCP
connect and device sign-ins, which the tab nonce does not cover.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… dropped where the page sends none

A dashboard SSO sign-in the server could not finish restarts at
/me?sign_in=sso, whose gate starts it again with a fresh tab nonce. That
address starts nothing after a sign-out. Behind a proxy that adds
Authorization, or with auth off, a #token= link is scrubbed and dropped
without asking. docs/architecture/security.md describes COOP once and adds
that a same-account token is stored once the server accepts it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…check retries a 503

/me?sign_in=sso starts SSO each time it is opened, unless the person signed
out: every ask takes a click on another page, so it cannot loop and the
five-minute guard on the automatic resume does not apply to it. The
same-account link check asks whoami through the same 503 retry as boot,
with the link's token in its own header.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… for

Any site could send the browser to /me?sign_in=sso and have the gate start a
sign-in whose token the tab then stores without the confirmation screen. The
dashboard page's boot snippet now carries __LOOM_OWN_ORIGIN, true only when
the load's Sec-Fetch-Site is same-origin or, from a browser that sends none,
when its Referer has Loom's public origin; the gate scrubs any other ask and
starts nothing for it.

Boot keeps whoami's answer for a same-account link's token instead of asking
again, and the link-mode tests wait for boot to finish.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ck handles default ports

Boot scrubs ?sign_in=sso next to the link token, signed in or not, and passes
whether it counts (a Loom page sent the browser there) to the gate, which
starts once for it. The Referer fallback compares origins with same_origin,
so a public URL that names its default port matches.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
A counted ask always follows a click on a Loom page, so the sign-out check
stays only on the automatic resume. A boot of /me?sign_in=sso that another
site sent starts nothing and shows the SSO button.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…e restart page links to the gate

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…account the server answered

Any link token this tab did not ask for is asked about with whoami, with its
own header, before anything else: one the server refuses or does not answer
is dropped without the screen, nothing stored and no other tab told; the
screen names the subject and org the server returned. A restart from the
landing keeps the start page the first sign-in saved.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…swer

A link token whoami refuses sets the gate's refused notice even when no
mark or held token sends boot there. Whether a link names the held account
compares the server's answer, not the link's unverified claims, and a
confirmed link's token is asked about again before boot uses it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…only a same-account answer

whoamiWhenReady(asToken) watched the stored token while it retried a 503,
so another tab changing or clearing it made up a refusal. With asToken the
stored token plays no part. Boot keeps the link's answer only when it names
the held account, so a confirmed token is asked about again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…n when another tab signs in

Whitespace is stripped from a link's token once, so whoami is asked about
the token setToken stores. The confirmation keeps the account held when it
was put, and puts the question again when another tab stored a different
token while it was up.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…he stored token

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 4a32187 into main Nov 7, 2026
38 checks passed
@zlareb1
zlareb1 deleted the sec/dashboard-link-token-confirm branch November 7, 2026 09:24
@zlareb1 zlareb1 mentioned this pull request Nov 12, 2026
3 tasks done
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