[PR #8968] [MERGED] fix(sso): normalize SAMLResponse whitespace at request boundary #16580

Closed
opened 2026-04-13 10:35:27 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8968
Author: @cyphercodes
Created: 4/5/2026
Status: Merged
Merged: 4/9/2026
Merged by: @gustavovalverde

Base: mainHead: fix/saml-whitespace-decoding


📝 Commits (4)

  • 99a2a73 fix(sso): strip whitespace from SAMLResponse before base64 decoding
  • af8934e fix(sso): normalize SAMLResponse whitespace at request boundary
  • 47b82f9 style(sso): format long line in validateSingleAssertion
  • e9b7bfe test(sso): cover CRLF, spaces, and tabs in whitespace stripping test

📊 Changes

4 files changed (+48 additions, -6 deletions)

View changed files

.changeset/saml-whitespace-decoding.md (+7 -0)
📝 packages/sso/src/routes/sso.ts (+10 -5)
📝 packages/sso/src/saml/assertions.test.ts (+28 -0)
📝 packages/sso/src/saml/assertions.ts (+3 -1)

📄 Description

Summary

Some SAML IDPs send SAMLResponse with line-wrapped base64 (per RFC 2045), which caused decoding failures with SAML_INVALID_ENCODING.

Whitespace is now stripped at the route extraction point so all downstream consumers (size check, assertion validation, signature verification, replay protection) operate on clean base64. The size limit check runs on the raw payload before stripping to prevent whitespace-padding bypass.

Fixes #8921

Test plan

  • Added unit test for RFC 2045 line-wrapped base64 input in assertions.test.ts

🔄 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/8968 **Author:** [@cyphercodes](https://github.com/cyphercodes) **Created:** 4/5/2026 **Status:** ✅ Merged **Merged:** 4/9/2026 **Merged by:** [@gustavovalverde](https://github.com/gustavovalverde) **Base:** `main` ← **Head:** `fix/saml-whitespace-decoding` --- ### 📝 Commits (4) - [`99a2a73`](https://github.com/better-auth/better-auth/commit/99a2a73eecdad0f45be1de685715eecf58fa536b) fix(sso): strip whitespace from SAMLResponse before base64 decoding - [`af8934e`](https://github.com/better-auth/better-auth/commit/af8934ee7d751dba761e0b753de377f5ae1b5c59) fix(sso): normalize SAMLResponse whitespace at request boundary - [`47b82f9`](https://github.com/better-auth/better-auth/commit/47b82f945409a02603a05c94965963e88e9a3df0) style(sso): format long line in validateSingleAssertion - [`e9b7bfe`](https://github.com/better-auth/better-auth/commit/e9b7bfee898ea08d7218d914d30af215ba4c9f26) test(sso): cover CRLF, spaces, and tabs in whitespace stripping test ### 📊 Changes **4 files changed** (+48 additions, -6 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/saml-whitespace-decoding.md` (+7 -0) 📝 `packages/sso/src/routes/sso.ts` (+10 -5) 📝 `packages/sso/src/saml/assertions.test.ts` (+28 -0) 📝 `packages/sso/src/saml/assertions.ts` (+3 -1) </details> ### 📄 Description ## Summary Some SAML IDPs send SAMLResponse with line-wrapped base64 (per RFC 2045), which caused decoding failures with `SAML_INVALID_ENCODING`. Whitespace is now stripped at the route extraction point so all downstream consumers (size check, assertion validation, signature verification, replay protection) operate on clean base64. The size limit check runs on the raw payload before stripping to prevent whitespace-padding bypass. Fixes #8921 ## Test plan - Added unit test for RFC 2045 line-wrapped base64 input in `assertions.test.ts` --- <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-13 10:35:28 -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#16580