Skip to content

fix(platform): bind organization session authority - #4903

Merged
yannickmonney merged 7 commits into
mainfrom
fix/organization-session-authority
Oct 12, 2026
Merged

yannickmonney merged 7 commits into
mainfrom
fix/organization-session-authority

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

Problem

Organization-scoped sessions could inherit stale or unbound authority, and a proxy-limited passkey ceremony could lose its role ceiling when the factor was used from a logged-out session.

Change

  • Add the additive 0203 authority ledger and operator-fenced legacy-session refusal inventory.
  • Bind session realm, trusted proxy role ceiling, fresh account proof, and active-team state to current persisted rows.
  • Make passkey registration/authentication preserve organization scope and stored role ceilings; malformed custody fails closed.
  • Keep existing REST, API-key, OAuth, SSO, two-factor, SSE, CLI and localized error contracts aligned.

Validation

  • Real owned PostgreSQL/WebAuthn proof: 29/29 pass, including previous-image compatibility, concurrent boot, rollback, historical/global and pure-SSO cases, proxy role-ceiling restoration, missing-custody refusal, and key/derivative controls.
  • Socket peak 3 during the explicitly allocated concurrent boot; original fixture schema/table/sequence inventory unchanged; fixture container stopped cleanly with original caps.
  • Focused authority Vitest: 55/55; authority sweep: 277/277; typecheck, lint, formatting, manual lint, conflict/link checks and targeted SAST passed.

@yannickmonney
yannickmonney force-pushed the fix/organization-session-authority branch from bc48c93 to 6384f7c Compare October 12, 2026 23:21
auto-merge was automatically disabled October 12, 2026 23:43

Merge commits are not allowed on this repository

@yannickmonney
yannickmonney merged commit 07419b9 into main Oct 12, 2026
@yannickmonney
yannickmonney deleted the fix/organization-session-authority branch October 12, 2026 23:43
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Review A follow-up (TALE-358, 2026-10-13 04:15 Zurich occurrence): user-facing and documentation impact of this merge, checked at main 715dc15ad.

  1. Members are told they aren't members. A session bound to one organization that opens another workspace gets ORG_FORBIDDEN and the session-restriction sentence. The dashboard maps that to accessDenied.noMembership ("You're not a member of this workspace. Contact an administrator for access."). Filed as bug(platform): a session bound to one organization is told it is "not a member" of the other workspaces it belongs to #4908, with the paths and a regression.
  2. TALE_ORG_SESSION_CUTOVER_AT is undocumented. It's a new operator setting that refuses boot when it isn't an exact past UTC timestamp (packages/shared/src/utils/org-session-cutover.ts; backend/env.ts:104-110). It appears in neither docs/*/self-hosted/configuration/environment-reference.md nor .env.example, and none of the docs explain when to set it, which is on a second rollout after the old writers retire.
  3. The v0.5.87 notes don't cover this merge (.github/release-notes/v0.5.87.md, if the release is cut from current main).
    • The migration line still names 0200–0202. main now also adds 0203_auth_factor_authorities.sql (this PR) and 0203_agent_connections.sql (feat(platform): connect coding agents to an organization #4899).
    • Nothing tells operators or people who sign in through single sign-on that such sessions are now limited to their organization.
    • Nothing describes the cutover setting.

This is static reading; I didn't run it.

@yannickmonney

Copy link
Copy Markdown
Contributor Author

Review A follow-up 2 (TALE-358, 2026-10-13 08:15 Zurich occurrence): the scheduled E2E run on main 715dc15ad fails two journeys at a member's sign-in after this merge.

  • Run: E2E 38339529780 (schedule, 02:59Z), job "Playwright (platform 4/4)" 115107517584. Both tests fail on all 3 attempts:
    • rbac.spec.ts:16, "admin adds a member who cannot see the add-member control";
    • return-loops.spec.ts:111, "return loop: assigning a task notifies and calls back the assignee".
  • Failure: POST /api/auth/sign-in/email for the member the admin just added answers 403 {"code":"ORG_FORBIDDEN","message":"This session is limited to the organization that signed you in."} (tests/e2e/helpers/auth.ts:81, called from rbac.spec.ts:74 and return-loops.spec.ts:212).
  • Why: during sign-in, this PR's session hooks raise that refusal only when the request already carries a valid session.
    • The pre-hook sets the mint authority from it (backend/auth/auth.ts:592); a malformed scope marker on it also refuses (passkey-authority.ts:90).
    • The session.create hook throws refuseScopedSession() when that authority belongs to another user (auth.ts:1007-1008).
    • So the member's second browser context sent another user's session cookie, most likely the admin's storage state, which the specs' fixture applies (tests/e2e/helpers/fixtures.ts:87-90).
  • To decide: either the specs sign the second user in from a clean context, or signing in as a different user should replace the presented session rather than refuse.
  • If the refusal is kept, its wording names the wrong cause. The sign-in page maps it to "wrong email or password" with the lockout hint (app/routes/_auth/log-in.tsx:253-256).
  • Coverage note: PR CI doesn't run the browser E2E, so this reached main red. 71 other platform journeys passed in the same run.

This is from the run's logs and a static reading of the cited lines.

yannickmonney added a commit that referenced this pull request Oct 13, 2026
The merge-group finisher only finishes a cancelled run whose workflow bytes it
has a reviewed profile for, so every change to cli.yml needs one (#4903 added
the previous). The CLI workflow now names domains/collab/service.ts in its push
paths, which changes its hash and left two tests red in Unit (workspaces):

- current seven workflows and verdict closure require an explicit reviewed
  profile on every source change
- current CLI path scope preserves the retained graph and every finishing
  refusal

Add the profile for the new bytes. The job and verdict graph is the one the
previous profile reviewed, so only the hash and its comment are new.
yannickmonney added a commit that referenced this pull request Oct 13, 2026
The dashboard test found the session-lapse dialog's confirm button by the bare
key `sessionLapse.signIn`, which only works while nothing has initialised the
i18n singleton: an uninitialised t() returns its key. #4903 made api-client
import auth-client-error, which imports the singleton, so from 07419b9 on the
dashboard's import graph initialises English and the button is named "Sign in".
The UI shard that holds the file has failed since (found by bisecting the test
alone: green at 6480ade, red at 07419b9, with no other change between).

Mock the translation hook the way the sibling session-lapse suites do, so the
accessible name is `auth.sessionLapse.signIn` whatever the graph initialises.
yannickmonney added a commit that referenced this pull request Oct 13, 2026
rbac.spec.ts and return-loops.spec.ts sign a member the admin just added in
from a second browser context and failed on every attempt since #4903 with
403 ORG_FORBIDDEN ("This session is limited to the organization that signed
you in"), which kept `Playwright (platform 4/4)` and so every release
candidate red.

The cause is in the specs, not the member: fixtures.ts overrides the
storageState option so every test authenticates as its worker's owner, and
that override also reaches every context made with browser.newContext() (shown
with a probe: the context holds the owner's cookie). The sign-in request then
presents the owner's session, and since #4903 minting a session for another
person from a presented session is refused.

Add newPersonContext(browser), a context from an empty cookie jar, and use it
for both members. What a browser holding another person's cookie should do when
someone signs in on it is a product decision and is not changed here.
tale-code-bot added a commit that referenced this pull request Oct 30, 2026
#4903 began writing trustedOrganizationId on every single sign-on
session, and useAuth().proxied read that column as the mark of a session
an authenticating proxy asserted. Single sign-on members lost Log out in
the account menu and Sign in again on the account-unavailable screen.
trustedRole holds the role a proxy asserted and single sign-on never
writes it, so proxied reads that now; a session a proxy asserted still
offers no sign-out of its own.
tale-code-bot added a commit that referenced this pull request Oct 30, 2026
Since #4903 the member door refuses a session bound to another
organization with 403 ORG_FORBIDDEN and the session's own sentence. The
member read mapped every ORG_FORBIDDEN to not_member, so a member who
signed in through organization A's single sign-on and opened a link into
B was told they are not a member of this workspace.

The read now answers session_restricted for that refusal, and the
dashboard says the session is limited to the organization that signed
the person in, with Sign in to this workspace: it ends the session and
takes the tab to sign-in, which brings them back here. The dashboard's
entry-failure page now uses the same useSignInAgain hook, so signing in
again has one copy. A session an authenticating proxy asserted gets no
button, since the proxy would sign it in to the same organization again.

Adds the AUTH-B25 manual box, its automation row and a troubleshooting
row in the enterprise SSO guide in English, German and French.
tale-review-bot pushed a commit that referenced this pull request Oct 30, 2026
Since #4903 the member door refuses a session bound to another
organization with 403 ORG_FORBIDDEN and the session's own sentence. The
member read mapped every ORG_FORBIDDEN to not_member, so a member who
signed in through organization A's single sign-on and opened a link into
B was told they are not a member of this workspace.

The read now answers session_restricted for that refusal, and the
dashboard says the session is limited to the organization that signed
the person in, with Sign in to this workspace: it ends the session and
takes the tab to sign-in, which brings them back here. The dashboard's
entry-failure page uses the same useSignInAgain hook, so signing in
again has one copy. A session an authenticating proxy asserted gets no
button, since the proxy would sign it in to the same organization again.

BackendApiError replaced the server's sentence with its translation when
it was built, so the refusal was recognized only in English; it is now
classified once, where the error is built, and kept as sessionRefusal.
useAuth().proxied read trustedOrganizationId, which #4903 writes on
every single sign-on session, so single sign-on members had lost Log out
and Sign in again; it now reads trustedRole, which holds the role an
authenticating proxy asserted and which single sign-on never writes.

Adds the AUTH-B25 manual box, its automation row and a troubleshooting
row in the enterprise SSO guide in English, German and French.

Closes #4908
Task: TALE-189
tale-review-bot pushed a commit that referenced this pull request Oct 30, 2026
Since #4903 a password sign-in carried the session the request presented
into the session it minted. When that session belonged to somebody else,
the sign-in was refused with 403 ORG_FORBIDDEN: an organization-limited
session or an API key before the password was checked, a global session
by the session-create hook after it. The log-in page words every such
refusal as a wrong password with the lockout hint, so a person signing
in on a browser where someone else was still signed in was told their
password was wrong.

The password is the proof of a sign-in as somebody else, so the
session-authority hook now drops the presented session when
/sign-in/email names another address than its user's, compared in the
canonical lower-case form: the sign-in mints exactly as from an empty
cookie jar, and its cookie replaces the presented one. The presented
session is not revoked; it stays its owner's to end. The same person's
sign-in, /reauthenticate and the two-factor verifications keep the
presented session's authority, and the session-create hook still refuses
a session for another person than the presented one.

The log-in page now words the refusal that remains, a sign-in over the
same person's organization-limited session, with the sentence the app
already uses for it instead of the wrong-password line and without the
lockout hint. The manual box AUTH-B27 walks both cases in one browser.

Closes #4919

Task: TALE-193
tale-code-bot added a commit that referenced this pull request Oct 31, 2026
Since #4903 the member door refuses a session bound to another
organization with 403 ORG_FORBIDDEN and the session's own sentence. The
member read mapped every ORG_FORBIDDEN to not_member, so a member who
signed in through organization A's single sign-on and opened a link into
B was told they are not a member of this workspace.

The read now answers session_restricted for that refusal, and the
dashboard says the session is limited to the organization that signed
the person in, with Sign in to this workspace: it ends the session and
takes the tab to sign-in, which brings them back here. The dashboard's
entry-failure page uses the same useSignInAgain hook, so signing in
again has one copy. A session an authenticating proxy asserted gets no
button, since the proxy would sign it in to the same organization again.

BackendApiError replaced the server's sentence with its translation when
it was built, so the refusal was recognized only in English; it is now
classified once, where the error is built, and kept as sessionRefusal.
useAuth().proxied read trustedOrganizationId, which #4903 writes on
every single sign-on session, so single sign-on members had lost Log out
and Sign in again; it now reads trustedRole, which holds the role an
authenticating proxy asserted and which single sign-on never writes.

Adds the AUTH-B25 manual box, its automation row and a troubleshooting
row in the enterprise SSO guide in English, German and French.

Closes #4908
Task: TALE-189
tale-code-bot added a commit that referenced this pull request Oct 31, 2026
Since #4903 a password sign-in carried the session the request presented
into the session it minted. When that session belonged to somebody else,
the sign-in was refused with 403 ORG_FORBIDDEN: an organization-limited
session or an API key before the password was checked, a global session
by the session-create hook after it. The log-in page words every such
refusal as a wrong password with the lockout hint, so a person signing
in on a browser where someone else was still signed in was told their
password was wrong.

The password is the proof of a sign-in as somebody else, so the
session-authority hook now drops the presented session when
/sign-in/email names another address than its user's, compared in the
canonical lower-case form: the sign-in mints exactly as from an empty
cookie jar, and its cookie replaces the presented one. The presented
session is not revoked; it stays its owner's to end. The same person's
sign-in, /reauthenticate and the two-factor verifications keep the
presented session's authority, and the session-create hook still refuses
a session for another person than the presented one.

The log-in page now words the refusal that remains, a sign-in over the
same person's organization-limited session, with the sentence the app
already uses for it instead of the wrong-password line and without the
lockout hint. The manual box AUTH-B27 walks both cases in one browser.

Closes #4919

Task: TALE-193
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