[PR #6503] [MERGED] feat(sso): add URL normalization and validation to all discovery URLs #32311

Closed
opened 2026-04-17 23:09:20 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6503
Author: @jonathansamines
Created: 12/3/2025
Status: Merged
Merged: 12/12/2025
Merged by: @Bekacru

Base: canaryHead: feat/sso-oidc-url-normalization


📝 Commits (10+)

  • 5762d8b feat(sso): add OIDC discovery pipeline module
  • 5d4b8a2 code challenge fix
  • 115f742 improve docu
  • 16a4f25 fix: just methods supported
  • 5cab5af fix: communicate methods out of scope
  • ffb99e6 feat: add more test and clear comments
  • 9863888 Merge branch 'canary' into feat/sso-oidc-discovery
  • b1d7450 fix: lint
  • e7b9125 feat(sso): integrate OIDC discovery into provider registration
  • ec42bd0 Merge branch 'canary' into feat/sso-oidc-discovery

📊 Changes

8 files changed (+603 additions, -54 deletions)

View changed files

📝 docs/content/docs/plugins/sso.mdx (+56 -0)
📝 packages/sso/src/oidc.test.ts (+3 -0)
📝 packages/sso/src/oidc/discovery.test.ts (+359 -25)
📝 packages/sso/src/oidc/discovery.ts (+168 -29)
📝 packages/sso/src/oidc/errors.ts (+6 -0)
📝 packages/sso/src/oidc/types.ts (+9 -0)
📝 packages/sso/src/routes/sso.ts (+1 -0)
📝 packages/sso/src/saml.test.ts (+1 -0)

📄 Description

What is changing?

This PR is build on top of #6456 and further improves our security posture by:

  • Normalizing all discovery related URLs to support relative paths
  • Validating all discovery related URLs
  • Making sure we apply the trustedOrigins policy to all downstream requests, improving our security posture by automatically protecting against SSRF vulnerabilities.

Note

: This PR is blocked by #6462, which will introduces the ctx.isTrustedOrigin() helper that we will use to apply the trusted origins policy to discovery urls.


Summary by cubic

Adds URL normalization and trusted-origin validation to OIDC discovery to resolve relative endpoints and block SSRF risks. Discovery now requires an isTrustedOrigin predicate and returns clearer errors.

  • New Features

    • Normalize authorization, token, JWKS, userinfo, revocation, end_session, and introspection URLs relative to the issuer (base path preserved).
    • Validate URLs and protocols; throw discovery_invalid_url for malformed or non-http/https.
    • Apply trustedOrigins to the main discovery URL and every discovered URL; throw discovery_untrusted_origin when untrusted.
    • Added isTrustedOrigin to discoverOIDCConfig params and mapped new errors to API responses.
    • Updated docs with examples and trustedOrigins guidance.
  • Migration

    • If you call discoverOIDCConfig directly, pass isTrustedOrigin (e.g., a predicate wired to your trustedOrigins).
    • Add your IdP domain(s) to trustedOrigins (e.g., https://your-org.okta.com).
    • registerSSOProvider now uses ctx.isTrustedOrigin; configure trustedOrigins or discovery will fail for untrusted URLs.

Written for commit 5e99ceb9ba. Summary will update automatically on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/6503 **Author:** [@jonathansamines](https://github.com/jonathansamines) **Created:** 12/3/2025 **Status:** ✅ Merged **Merged:** 12/12/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `feat/sso-oidc-url-normalization` --- ### 📝 Commits (10+) - [`5762d8b`](https://github.com/better-auth/better-auth/commit/5762d8b769d265510c9defe9bc2cdfbfc9ea8715) feat(sso): add OIDC discovery pipeline module - [`5d4b8a2`](https://github.com/better-auth/better-auth/commit/5d4b8a2b62c13f576770164afbd880e0e5bab430) code challenge fix - [`115f742`](https://github.com/better-auth/better-auth/commit/115f7427ee5ff4fd1893eeef61d3ceedd8fa0a74) improve docu - [`16a4f25`](https://github.com/better-auth/better-auth/commit/16a4f25d8871e1e40f843c7b16675e70e05bd949) fix: just methods supported - [`5cab5af`](https://github.com/better-auth/better-auth/commit/5cab5af9096ace10df2e59ced6b8b37bf9f34a92) fix: communicate methods out of scope - [`ffb99e6`](https://github.com/better-auth/better-auth/commit/ffb99e6f21358be096a22370da03df57f486f3cc) feat: add more test and clear comments - [`9863888`](https://github.com/better-auth/better-auth/commit/9863888be9c1d4e4d4a20cfac2c8533dadf2ec4a) Merge branch 'canary' into feat/sso-oidc-discovery - [`b1d7450`](https://github.com/better-auth/better-auth/commit/b1d7450803a7e55e7efa0c6ebad2f34e1d9e9bd1) fix: lint - [`e7b9125`](https://github.com/better-auth/better-auth/commit/e7b91259b455ec27205e0e6d6f03a9ac4fe36521) feat(sso): integrate OIDC discovery into provider registration - [`ec42bd0`](https://github.com/better-auth/better-auth/commit/ec42bd05bc87b64ee9d715688b51f60fd8d3b7a4) Merge branch 'canary' into feat/sso-oidc-discovery ### 📊 Changes **8 files changed** (+603 additions, -54 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/sso.mdx` (+56 -0) 📝 `packages/sso/src/oidc.test.ts` (+3 -0) 📝 `packages/sso/src/oidc/discovery.test.ts` (+359 -25) 📝 `packages/sso/src/oidc/discovery.ts` (+168 -29) 📝 `packages/sso/src/oidc/errors.ts` (+6 -0) 📝 `packages/sso/src/oidc/types.ts` (+9 -0) 📝 `packages/sso/src/routes/sso.ts` (+1 -0) 📝 `packages/sso/src/saml.test.ts` (+1 -0) </details> ### 📄 Description **What is changing?** This PR is build on top of #6456 and further improves our security posture by: - Normalizing all discovery related URLs to support relative paths - Validating all discovery related URLs - Making sure we apply the `trustedOrigins` policy to all downstream requests, improving our security posture by automatically protecting against [`SSRF` ](https://portswigger.net/web-security/ssrf) vulnerabilities. > **Note**: This PR is blocked by #6462, which will introduces the `ctx.isTrustedOrigin()` helper that we will use to apply the trusted origins policy to discovery urls. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds URL normalization and trusted-origin validation to OIDC discovery to resolve relative endpoints and block SSRF risks. Discovery now requires an isTrustedOrigin predicate and returns clearer errors. - **New Features** - Normalize authorization, token, JWKS, userinfo, revocation, end_session, and introspection URLs relative to the issuer (base path preserved). - Validate URLs and protocols; throw discovery_invalid_url for malformed or non-http/https. - Apply trustedOrigins to the main discovery URL and every discovered URL; throw discovery_untrusted_origin when untrusted. - Added isTrustedOrigin to discoverOIDCConfig params and mapped new errors to API responses. - Updated docs with examples and trustedOrigins guidance. - **Migration** - If you call discoverOIDCConfig directly, pass isTrustedOrigin (e.g., a predicate wired to your trustedOrigins). - Add your IdP domain(s) to trustedOrigins (e.g., https://your-org.okta.com). - registerSSOProvider now uses ctx.isTrustedOrigin; configure trustedOrigins or discovery will fail for untrusted URLs. <sup>Written for commit 5e99ceb9bab5709af4e0c6c9620da1ed5a476fd4. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-17 23:09:20 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#32311