fix(auth): trust public-routable external-IdP origins at SSO registration (ADR-0024 / cloud#551)#2370
Merged
Merged
Conversation
…tion (ADR-0024 / cloud#551) @better-auth/sso's discovery validation requires every IdP endpoint origin to be in trustedOrigins — even for a publicly-routable IdP — so registering any external IdP returned 400 discovery_untrusted_origin unless pre-listed in boot config, breaking ADR-0024's runtime self-service promise. When the SSO RP is enabled, expose trustedOrigins as a per-request function that, for POST /sso/register|/sso/update-provider, additionally trusts the PUBLIC-ROUTABLE issuer/oidcConfig endpoint origins from the request body (@better-auth/core isPublicRoutableHost). Private/internal/loopback hosts are never auto-trusted; better-auth's DNS-resolution checks still apply. Verified E2E: a same-origin public IdP (GitLab.com) now registers at runtime with no boot config (was 400); the admin gate still fires before discovery. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📓 Docs Drift CheckThis PR changes 1 package(s): 10 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
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.
Why
Follow-up to #2363 (the cloud#551 SSO admin-gate). Local E2E surfaced a second gap:
@better-auth/sso's discovery validation (validateDiscoveryUrl+normalizeAndValidateUrl) requires every IdP endpoint origin to be intrustedOrigins— even for a publicly-routable IdP. So registering any external OIDC IdP returns400 discovery_untrusted_originunless the operator pre-listed it, which breaks ADR-0024's "register your IdP at runtime, no boot config" promise.What
When the external-SSO RP is enabled (
isSsoWired()),trustedOriginsis now a per-request function that, for aPOST /sso/register|/sso/update-provider, additionally trusts the public-routable issuer /oidcConfigendpoint origins declared in the request body — using@better-auth/core's ownisPublicRoutableHost(the same predicate better-auth's sub-endpoint check uses). All other requests get exactly the previous static origins.Safety:
trustedOriginsconfig (the documented SSRF escape hatch).Verification (browser E2E, local prod-like stack, no trustedOrigins entry)
400).googleapis.comendpoint origins trusted (documented caveat — multi-domain IdPs).Scope
Only
packages/plugins/plugin-auth/src/auth-manager.ts(+ changeset). SSO mechanism stays framework-open.🤖 Generated with Claude Code