[GH-ISSUE #8921] (SSO) SAML_INVALID_ENCODING when SAMLResponse base64 contains spaces #11237

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

Originally created by @rphlmr on GitHub (Apr 2, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/8921

Is this suited for github?

  • Yes, this is suited for github

Reproduction

Receive a SAMLResponse base64 that contains spaces.

Current vs. Expected behavior

We encountered an issue with our SAML IDP that sends a SAMLResponse containing spaces in the base64 string. A quick fix is to apply this in validateSingleAssertion:

-		xml = new TextDecoder().decode(base64.decode(samlResponse));
+		xml = new TextDecoder().decode(base64.decode(samlResponse.replace(/\s+/g, "")));

4742f349dc/packages/sso/src/saml/assertions.ts (L36)

Do you think it should be fixed in the SSO plugin?

What version of Better Auth are you using?

1.5.6

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 25.4.0: Thu Mar 19 19:31:09 PDT 2026; root:xnu-12377.101.15~1/RELEASE_ARM64_T8132",
    "release": "25.4.0",
    "cpuCount": 10,
    "cpuModel": "Apple M4",
    "totalMemory": "16.00 GB",
    "freeMemory": "0.49 GB"
  },
  "node": {
    "version": "v24.14.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.9.0"
  },
  "frameworks": [
    {
      "name": "react",
      "version": "19.2.4"
    },
    {
      "name": "hono",
      "version": "4.12.9"
    },
    {
      "name": "react-router",
      "version": "7.13.2"
    }
  ],
  "databases": [
    {
      "name": "pg",
      "version": "8.20.0"
    }
  ],
  "betterAuth": {
    "version": "1.5.6",
    "config": null
  }
}

Which area(s) are affected? (Select all that apply)

Package

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

No response

Originally created by @rphlmr on GitHub (Apr 2, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/8921 ### Is this suited for github? - [x] Yes, this is suited for github ### Reproduction Receive a `SAMLResponse` base64 that contains spaces. ### Current vs. Expected behavior We encountered an issue with our SAML IDP that sends a `SAMLResponse` containing spaces in the base64 string. A quick fix is to apply this in `validateSingleAssertion`: ```diff - xml = new TextDecoder().decode(base64.decode(samlResponse)); + xml = new TextDecoder().decode(base64.decode(samlResponse.replace(/\s+/g, ""))); ``` https://github.com/better-auth/better-auth/blob/4742f349dcae607fe5c79a32196ab8c03977500b/packages/sso/src/saml/assertions.ts#L36 Do you think it should be fixed in the SSO plugin? ### What version of Better Auth are you using? 1.5.6 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 25.4.0: Thu Mar 19 19:31:09 PDT 2026; root:xnu-12377.101.15~1/RELEASE_ARM64_T8132", "release": "25.4.0", "cpuCount": 10, "cpuModel": "Apple M4", "totalMemory": "16.00 GB", "freeMemory": "0.49 GB" }, "node": { "version": "v24.14.0", "env": "development" }, "packageManager": { "name": "npm", "version": "11.9.0" }, "frameworks": [ { "name": "react", "version": "19.2.4" }, { "name": "hono", "version": "4.12.9" }, { "name": "react-router", "version": "7.13.2" } ], "databases": [ { "name": "pg", "version": "8.20.0" } ], "betterAuth": { "version": "1.5.6", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-04-13 07:35:02 -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#11237