[PR #6048] [CLOSED] fix: support WantAuthnRequestsSigned="true" for sso SAML SPs #32007

Closed
opened 2026-04-17 22:52:46 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6048
Author: @jzylks
Created: 11/17/2025
Status: Closed

Base: mainHead: bugfix/sign-authn-requests


📝 Commits (5)

  • 6811fca Bugfix: support WantAuthnRequestsSigned="true" for sso SAML SPs
  • bfa48c7 Update packages/sso/src/saml.test.ts
  • e97481a Update packages/sso/src/routes/sso.ts
  • 0519daa Update packages/sso/src/saml.test.ts
  • 735f5fd fix(sso): clean up ServiceProvider initialization and remove unnecessary whitespace

📊 Changes

2 files changed (+201 additions, -7 deletions)

View changed files

📝 packages/sso/src/routes/sso.ts (+13 -7)
📝 packages/sso/src/saml.test.ts (+188 -0)

📄 Description

The sso package cannot currently authenticate with a SAML IDP that requires signed authentication requests. There are a couple problems:

  • If the SP metadata includes AuthnRequestsSigned="true", samlify will throw an error when constructing the ServiceProvider object because the private key (and optional private key password) are not included in the samlConfig object. Only the metadata and allowCreate are currently set.
  • After adding the private key for signing, the request to the IDP cannot be validated because the RelayState is added to the URL after the request has been signed.

This adds the private key and private key password to the constructor for the samlify ServiceProvider object so that it is able to sign the request, and moves the relayState to that same constructor so that it is included in the signature.


Summary by cubic

Adds support for SAML IDPs that require signed Authn requests (WantAuthnRequestsSigned="true"). Authn requests are now signed by the SP and include RelayState in the signature so IDP validation succeeds.

  • Bug Fixes
    • Pass privateKey and privateKeyPass from spMetadata to the samlify ServiceProvider.
    • Set relayState in the ServiceProvider constructor and stop appending RelayState after signing.
    • Added tests covering IDPs that require signed Authn requests.

Written for commit 735f5fd700. 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/6048 **Author:** [@jzylks](https://github.com/jzylks) **Created:** 11/17/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `bugfix/sign-authn-requests` --- ### 📝 Commits (5) - [`6811fca`](https://github.com/better-auth/better-auth/commit/6811fca24e345b4717f4739ec96acc95b43d994b) Bugfix: support `WantAuthnRequestsSigned="true"` for sso SAML SPs - [`bfa48c7`](https://github.com/better-auth/better-auth/commit/bfa48c7fe802e4e5ef297c8a7b79b9f609d15dd9) Update packages/sso/src/saml.test.ts - [`e97481a`](https://github.com/better-auth/better-auth/commit/e97481a3fc604cf55e420a5fc3f1af45cb2abc61) Update packages/sso/src/routes/sso.ts - [`0519daa`](https://github.com/better-auth/better-auth/commit/0519daab2c439704e9a8858b073797104e961782) Update packages/sso/src/saml.test.ts - [`735f5fd`](https://github.com/better-auth/better-auth/commit/735f5fd7009da949689fd19c929a2f9cf9bb7bf6) fix(sso): clean up ServiceProvider initialization and remove unnecessary whitespace ### 📊 Changes **2 files changed** (+201 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `packages/sso/src/routes/sso.ts` (+13 -7) 📝 `packages/sso/src/saml.test.ts` (+188 -0) </details> ### 📄 Description The `sso` package cannot currently authenticate with a SAML IDP that requires signed authentication requests. There are a couple problems: - If the SP metadata includes `AuthnRequestsSigned="true"`, samlify will throw an error when constructing the ServiceProvider object because the private key (and optional private key password) are not included in the samlConfig object. Only the metadata and `allowCreate` are currently set. - After adding the private key for signing, the request to the IDP cannot be validated because the `RelayState` is added to the URL after the request has been signed. This adds the private key and private key password to the constructor for the samlify ServiceProvider object so that it is able to sign the request, and moves the relayState to that same constructor so that it is included in the signature. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds support for SAML IDPs that require signed Authn requests (WantAuthnRequestsSigned="true"). Authn requests are now signed by the SP and include RelayState in the signature so IDP validation succeeds. - **Bug Fixes** - Pass privateKey and privateKeyPass from spMetadata to the samlify ServiceProvider. - Set relayState in the ServiceProvider constructor and stop appending RelayState after signing. - Added tests covering IDPs that require signed Authn requests. <sup>Written for commit 735f5fd7009da949689fd19c929a2f9cf9bb7bf6. 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 22:52:46 -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#32007