[PR #7668] [CLOSED] fix(saml): IdP-Initiated Callback Routing (#6675) #33082

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7668
Author: @Paola3stefania
Created: 1/28/2026
Status: Closed

Base: mainHead: fix/saml-idp-initiated-callback-routing


📝 Commits (5)

  • d1602ef fix: correctly handle OAuth callback and Apple email field (#7181)
  • e5f3871 fix(saml): IdP-Initiated Callback Routing (#6675)
  • 1205a34 chore: improve rate limiting type definitions (#7313)
  • 9c8aad6 Merge origin/main into fix/saml-idp-initiated-callback-routing
  • 3427771 fix: restore getPlugin type in AuthContext after merge

📊 Changes

20 files changed (+1981 additions, -367 deletions)

View changed files

📝 docs/content/docs/guides/saml-sso-with-okta.mdx (+6 -1)
📝 docs/content/docs/plugins/sso.mdx (+40 -1)
📝 packages/better-auth/src/api/index.ts (+2 -8)
📝 packages/better-auth/src/api/middlewares/origin-check.ts (+19 -2)
📝 packages/better-auth/src/api/rate-limiter/index.ts (+47 -35)
📝 packages/better-auth/src/api/routes/callback.ts (+23 -2)
📝 packages/better-auth/src/context/create-context.ts (+3 -1)
📝 packages/better-auth/src/context/helpers.ts (+1 -1)
📝 packages/better-auth/src/oauth2/state.ts (+20 -164)
📝 packages/better-auth/src/social.test.ts (+172 -1)
packages/better-auth/src/state.ts (+221 -0)
📝 packages/better-auth/src/utils/index.ts (+2 -0)
📝 packages/core/src/social-providers/apple.ts (+12 -3)
📝 packages/core/src/types/context.ts (+4 -4)
📝 packages/core/src/types/index.ts (+2 -0)
📝 packages/core/src/types/init-options.ts (+26 -32)
📝 packages/sso/src/index.ts (+22 -0)
📝 packages/sso/src/routes/sso.ts (+145 -15)
packages/sso/src/saml-state.ts (+78 -0)
📝 packages/sso/src/saml.test.ts (+1136 -97)

📄 Description

Summary by cubic

Fixes IdP-initiated SAML callback routing so users coming from the IdP dashboard land in the right place. The SAML callback now supports both GET and POST, validates redirects, and skips origin checks for IdP posts to address the routing issue for IdP-initiated SSO.

  • Bug Fixes

    • Handle IdP-initiated SSO: GET on /sso/saml2/callback/:providerId now redirects using session state.
    • Prevent open redirects and callback loops with strict redirect validation (relative paths or trusted origins only).
    • Normalize path handling in middleware and rate limiter via normalizePathname.
    • Improve origin check middleware with path-based skipping and clear CSRF back-compat.
  • New Features

    • Secure RelayState generation/parsing for SAML (backed by new generic state utilities).
    • SAML callback accepts both GET and POST; ACS route updated and supports default providerId.
    • SSO plugin auto-skips origin checks for SAML callback and ACS endpoints to allow IdP POSTs.
    • Docs updated to use the callback URL for IdP-initiated flows and to set callbackUrl to the app destination (not the callback route). Remove any custom GET handler for the callback after upgrading.

Written for commit 34277714f8. Summary will update 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/7668 **Author:** [@Paola3stefania](https://github.com/Paola3stefania) **Created:** 1/28/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/saml-idp-initiated-callback-routing` --- ### 📝 Commits (5) - [`d1602ef`](https://github.com/better-auth/better-auth/commit/d1602ef0ae9822e462a5a42497072a0a1756e804) fix: correctly handle OAuth callback and Apple email field (#7181) - [`e5f3871`](https://github.com/better-auth/better-auth/commit/e5f38719b807cfc2404c548ab9d4715b9905c9d8) fix(saml): IdP-Initiated Callback Routing (#6675) - [`1205a34`](https://github.com/better-auth/better-auth/commit/1205a349cd7829d65f388e9dbdaf2a93b9b44f7a) chore: improve rate limiting type definitions (#7313) - [`9c8aad6`](https://github.com/better-auth/better-auth/commit/9c8aad688e5c6312cf9f48683e847a8233ad4dd8) Merge origin/main into fix/saml-idp-initiated-callback-routing - [`3427771`](https://github.com/better-auth/better-auth/commit/34277714f8871da2ec7566fcbc96790fbbf59f61) fix: restore getPlugin type in AuthContext after merge ### 📊 Changes **20 files changed** (+1981 additions, -367 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/guides/saml-sso-with-okta.mdx` (+6 -1) 📝 `docs/content/docs/plugins/sso.mdx` (+40 -1) 📝 `packages/better-auth/src/api/index.ts` (+2 -8) 📝 `packages/better-auth/src/api/middlewares/origin-check.ts` (+19 -2) 📝 `packages/better-auth/src/api/rate-limiter/index.ts` (+47 -35) 📝 `packages/better-auth/src/api/routes/callback.ts` (+23 -2) 📝 `packages/better-auth/src/context/create-context.ts` (+3 -1) 📝 `packages/better-auth/src/context/helpers.ts` (+1 -1) 📝 `packages/better-auth/src/oauth2/state.ts` (+20 -164) 📝 `packages/better-auth/src/social.test.ts` (+172 -1) ➕ `packages/better-auth/src/state.ts` (+221 -0) 📝 `packages/better-auth/src/utils/index.ts` (+2 -0) 📝 `packages/core/src/social-providers/apple.ts` (+12 -3) 📝 `packages/core/src/types/context.ts` (+4 -4) 📝 `packages/core/src/types/index.ts` (+2 -0) 📝 `packages/core/src/types/init-options.ts` (+26 -32) 📝 `packages/sso/src/index.ts` (+22 -0) 📝 `packages/sso/src/routes/sso.ts` (+145 -15) ➕ `packages/sso/src/saml-state.ts` (+78 -0) 📝 `packages/sso/src/saml.test.ts` (+1136 -97) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Fixes IdP-initiated SAML callback routing so users coming from the IdP dashboard land in the right place. The SAML callback now supports both GET and POST, validates redirects, and skips origin checks for IdP posts to address the routing issue for IdP-initiated SSO. - **Bug Fixes** - Handle IdP-initiated SSO: GET on `/sso/saml2/callback/:providerId` now redirects using session state. - Prevent open redirects and callback loops with strict redirect validation (relative paths or trusted origins only). - Normalize path handling in middleware and rate limiter via `normalizePathname`. - Improve origin check middleware with path-based skipping and clear CSRF back-compat. - **New Features** - Secure RelayState generation/parsing for SAML (backed by new generic state utilities). - SAML callback accepts both GET and POST; ACS route updated and supports default `providerId`. - SSO plugin auto-skips origin checks for SAML callback and ACS endpoints to allow IdP POSTs. - Docs updated to use the callback URL for IdP-initiated flows and to set `callbackUrl` to the app destination (not the callback route). Remove any custom GET handler for the callback after upgrading. <sup>Written for commit 34277714f8871da2ec7566fcbc96790fbbf59f61. Summary will update 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:44:59 -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#33082