Repository navigation
fix(auth): SSO sign-in keeps the safe pre-login redirect - #36778
Merged
Merged
Conversation
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbWcpizQKnJmTb6cTpa
Contributor
Author
|
repo:objectstack#1 · os-warren · session_01JQwxbZeHNsF3RWcWpj7rGj 维护者速读没登录时打开一条记录的链接,用「公司邮箱 SSO」登录后,现在会回到那条记录,不再落到最近用的应用。只认本站内的链接,外站地址一律丢掉。 席位核对 — ACCEPT (L1) · repo:objectstack#1 · head
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Warren · project thread
Fixes #36754
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
LoginForm's "Sign in with SSO" (email-domain SSO,POST /api/v1/auth/sign-in/sso) built itscallbackURLfrom the console base plus a fixed/, so the?redirect=the sign-in page carries was lost. It now:?redirect=on the sign-in page, sendscallbackURL= the sign-in page's own path with only that redirect (/login?redirect=ENCODED, or/_console/login?redirect=ENCODEDunder 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 ownisSafeRedirect. This is the same return the provider buttons (SocialSignInButtons, default callback = the current page) and direct sign-in (directSignInStartUrl) already use;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). Onlyredirecttravels, never the rest of the query (a previous attempt'serrorwould 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 itscallbackURL; 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./loginreturns to/login?redirect=ENCODED, and the redirect decodes back to the record path;/_console/loginwitherror/error_descriptionbeside it: returns to/_console/login?redirect=ENCODED, nothing else carried;/: absolute URL, protocol-relative//host, a non-root-relative path, an empty value;/_console/;/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(fromui/): Test Files 2 passed (2), Tests 46 passed (46).pnpm --filter @object-ui/auth type-checkthenpnpm exec vitest run packages/auth/: exit 0, Test Files 49 passed (49), Tests 502 passed (502).LoginForm.tsxtaken fromorigin/main,ssoCallbackURLcount 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 withgit checkout HEAD --, blob hash equal to HEAD's (eaba863d).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
@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.isSafeRelativeURL, better-auth 1.7.12) refuses protocol-relative values and encoded separators in the path; the redirect rides the query, percent-encoded byencodeURIComponent.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.tsxssoCallbackURL(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