Skip to content

fix(auth): SSO sign-in keeps the safe pre-login redirect - #36778

Merged
objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/project-thread-pgfx35
Nov 23, 2026
Merged

objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/project-thread-pgfx35

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Warren · project thread

Fixes #36754

Clause-②: no
Metadata-protocol: none

维护者速读

  • 未登录的人打开一条记录链接,用工作邮箱走 SSO 登录后,现在回到那条记录;以前落到上次用的应用。
  • 补齐登录体验:密码登录和第三方账号按钮早就会带人回原链接,只有邮箱 SSO 漏了。
  • 只认本站内的链接,外站地址一律丢弃、照常落到默认应用;出错最多是落回默认应用,可直接撤回。
  • 无。

What changes

LoginForm's "Sign in with SSO" (email-domain SSO, POST /api/v1/auth/sign-in/sso) built its callbackURL from the console base plus a fixed /, so the ?redirect= the sign-in page carries was lost. It now:

  • with a safe ?redirect= on the sign-in page, sends callbackURL = the sign-in page's own path with only that redirect (/login?redirect=ENCODED, or /_console/login?redirect=ENCODED under a mount). The identity provider returns the browser to the sign-in page, which finishes sign-in its own way (org auto-select, the mobile hand-off, the OAuth-provider replay) and then lands on the link through its own isSafeRedirect. This is the same return the provider buttons (SocialSignInButtons, default callback = the current page) and direct sign-in (directSignInStartUrl) already use;
  • with no redirect or an unsafe one, keeps callbackURL = base + / exactly as before (电脑端登录直接进上次用的应用,平台首页下线(#36107 第二阶段) #36732).

"Safe" is the console LoginPage's own rule, byte for byte: starts with / and not //. It is not loosened, and the console page applies it again on the final hop. The predicate stays module-private (no new export). Only redirect travels, never the rest of the query (a previous attempt's error would otherwise come back with a successful sign-in).

Why back to the sign-in page rather than straight to base + redirect: the mobile hand-off rules (handoffRedirect.ts, rule 2) say the hand-off route is never handed to a provider as its callbackURL; going through the sign-in page keeps that, and keeps the org auto-select step a direct landing would skip.

Tests

New ui/packages/auth/src/__tests__/ssoCallbackRedirect-36754.test.tsx (8 tests) drives the real form: sets the page URL, presses "Sign in with SSO", reads the request body.

  • safe redirect at /login returns to /login?redirect=ENCODED, and the redirect decodes back to the record path;
  • under /_console/login with error / error_description beside it: returns to /_console/login?redirect=ENCODED, nothing else carried;
  • dropped, callback /: absolute URL, protocol-relative //host, a non-root-relative path, an empty value;
  • unsafe redirect under the mount: callback /_console/;
  • CONTROL: no redirect gives / and /_console/, as before.
Readings (head dcd0d78)
  • pnpm exec vitest run packages/auth/src/__tests__/ssoCallbackRedirect-36754.test.tsx packages/auth/src/__tests__/LoginForm.test.tsx (from ui/): Test Files 2 passed (2), Tests 46 passed (46).
  • pnpm --filter @object-ui/auth type-check then pnpm exec vitest run packages/auth/: exit 0, Test Files 49 passed (49), Tests 502 passed (502).
  • Ablation (fix committed first, LoginForm.tsx taken from origin/main, ssoCallbackURL count 0 on disk): the two carry tests turn red (2 failed | 6 passed (8)); the drop and control tests stay green, as expected, since main always drops. Restored with git checkout HEAD --, blob hash equal to HEAD's (eaba863d).
  • Local gates: check-changeset-no-major, check-empty-changeset, check-adr-0087-registration (all --base origin/main), check:nul-bytes, check-sdui-manifest: exit 0. overlap-check: VERDICT clean. Every other derived family is left to this PR's CI.

Acceptance notes

  • Browser check: NOT MEASURED, no SSO provider locally. Email-domain SSO needs a registered identity provider (@better-auth/sso), which a local dev stack does not have, so the browser leg is pinned by the test above, as the card allows.
  • better-auth accepts the new callback: its relative-path check (isSafeRelativeURL, better-auth 1.7.12) refuses protocol-relative values and encoded separators in the path; the redirect rides the query, percent-encoded by encodeURIComponent.
  • The package's other sign-in page, app-shell's exported DefaultLoginPage, has no in-repo user and does not honour ?redirect= for any sign-in (its password success navigates to /). Through it, SSO now returns to that page like its provider buttons already do. Noted, not changed.

Verification

Read first: ui/packages/auth/src/LoginForm.tsx ssoCallbackURL (the only behaviour change), then the new test file.

Two-minute check: from ui/, pnpm exec vitest run packages/auth/src/__tests__/ssoCallbackRedirect-36754.test.tsx: expect 8 passed.


Generated by Claude Code

@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 23, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbZeHNsF3RWcWpj7rGj

维护者速读

没登录时打开一条记录的链接,用「公司邮箱 SSO」登录后,现在会回到那条记录,不再落到最近用的应用。只认本站内的链接,外站地址一律丢掉。
要你做的:无(普通改动,席位自动合并)。

席位核对 — ACCEPT (L1) · repo:objectstack#1 · head dcd0d78e · 2026-11-23T22:07Z

  • Shape: Fixes #36754. ui/packages/auth/src/LoginForm.tsx (+28 −5), one new test file, a patch changeset for @object-ui/auth. Not a governed path; no contract face. Clause-②: no (the helper is module-private). Metadata-protocol: none.
  • Read: handleSso now sends callbackURL from a module-private ssoCallbackURL(). With a same-origin ?redirect= it returns to the sign-in page carrying only that redirect, the same return the provider buttons use; without one, or with an unsafe one, it is the console root as before. The same-origin rule is the console sign-in page's own, unchanged and not loosened, and that page applies it again on the final hop.
  • Tests: 4 cases plus a 4-row table: a safe redirect kept; only the redirect carried under the console mount; absolute, protocol-relative, non-root-relative and empty values dropped; the no-redirect control unchanged. The thread reports the 2 carry tests go red with the change removed.
  • Not measured: the browser leg (no SSO provider locally), pinned by test as the card allows.
  • Gates: 39 success, 13 expected skip, 0 failed on dcd0d78e; mergeable_state clean.
  • Landing: the seat readies the PR and arms auto-merge.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 23, 2026 22:09
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit 79a355b Nov 23, 2026
53 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-pgfx35 branch November 23, 2026 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

邮箱域名 SSO 登录丢掉登录前的跳转地址:未登录打开记录链接、走 SSO 登录后落到应用而不是那条记录

2 participants