Skip to content

Commit 45d5d64

Browse files
waleedlatif1claude
andcommitted
fix(auth): address review — guard trusted SSO providers, revert invite callback
- Only compute additionalTrustedSsoProviders when SSO_ENABLED, so trustedProviders is exactly unchanged for non-SSO deployments. - Revert the invite getCallbackUrl change: keep the token in the callback URL (with sessionStorage/searchParams fallback) so the token survives when sessionStorage is unavailable. The account-linking fix removes the "account not linked" error that caused the malformed callback URL, so the callback cleanup is unnecessary. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent b07ee18 commit 45d5d64

2 files changed

Lines changed: 14 additions & 16 deletions

File tree

apps/sim/app/invite/[id]/invite.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,11 @@ export default function Invite() {
255255
}
256256
}
257257

258-
/**
259-
* Post-authentication return URL. Omits the token query string: Better Auth
260-
* appends `?error=<message>` onto callbackURL unescaped, producing a malformed
261-
* URL that fails its callbackURL validation. The token is persisted to
262-
* sessionStorage on mount and rehydrated on return, so it need not ride in the URL.
263-
*/
264-
const getCallbackUrl = () => `/invite/${inviteId}`
258+
const getCallbackUrl = () => {
259+
const effectiveToken =
260+
token || sessionStorage.getItem(inviteTokenStorageKey) || searchParams.get('token')
261+
return `/invite/${inviteId}${effectiveToken ? `?token=${effectiveToken}` : ''}`
262+
}
265263

266264
if (!session?.user && !isPending) {
267265
const callbackUrl = encodeURIComponent(getCallbackUrl())

apps/sim/lib/auth/auth.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,16 @@ const additionalTrustedOrigins = parseOriginList(env.TRUSTED_ORIGINS, (value) =>
167167
/**
168168
* SSO provider IDs to trust for automatic account linking when an SSO sign-in
169169
* matches an existing account's email. Includes `SSO_PROVIDER_ID` when it is set
170-
* in the app environment, plus any IDs from `SSO_TRUSTED_PROVIDER_IDS`. Resolved
171-
* once at startup; `trustEmailVerified` on the SSO plugin handles IdPs that assert
172-
* `email_verified` live, so this is only needed for IdPs that omit that claim.
170+
* in the app environment, plus any IDs from `SSO_TRUSTED_PROVIDER_IDS`. Empty when
171+
* SSO is disabled, so `trustedProviders` is unchanged for non-SSO deployments.
172+
* Resolved once at startup; `trustEmailVerified` on the SSO plugin handles IdPs
173+
* that assert `email_verified` live, so this is only needed for IdPs that omit it.
173174
*/
174-
const additionalTrustedSsoProviders = [
175-
env.SSO_PROVIDER_ID,
176-
...(env.SSO_TRUSTED_PROVIDER_IDS?.split(',') ?? []),
177-
]
178-
.map((id) => id?.trim())
179-
.filter((id): id is string => Boolean(id))
175+
const additionalTrustedSsoProviders = env.SSO_ENABLED
176+
? [env.SSO_PROVIDER_ID, ...(env.SSO_TRUSTED_PROVIDER_IDS?.split(',') ?? [])]
177+
.map((id) => id?.trim())
178+
.filter((id): id is string => Boolean(id))
179+
: []
180180

181181
if (env.NODE_ENV === 'production') {
182182
const baseUrl = getBaseUrl()

0 commit comments

Comments
 (0)