[PR #6712] [CLOSED] fix(oidc-provider): enforce JWT plugin for public clients to prevent zero-length key crash #23744

Closed
opened 2026-04-15 21:57:01 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6712
Author: @GautamBytes
Created: 12/12/2025
Status: Closed

Base: mainHead: fix/oidc-public-client-signing


📝 Commits (2)

  • fdeaff4 fix(oidc-provider): prevent crash when signing ID tokens for public clients
  • 6bc17dd added test cases

📊 Changes

2 files changed (+228 additions, -0 deletions)

View changed files

📝 packages/better-auth/src/plugins/oidc-provider/index.ts (+16 -0)
📝 packages/better-auth/src/plugins/oidc-provider/oidc.test.ts (+212 -0)

📄 Description

Description

Fixes #6651

This PR addresses a runtime crash ("Zero-length key is not supported") that occurs when a Public Client (e.g., mobile app, SPA) attempts to obtain an ID Token using the OIDC provider.

The Issue

Currently, the OIDC provider defaults to symmetric signing (HS256) using the clientSecret if the jwt plugin is not explicitly enabled. Public clients (using PKCE) correctly have clientSecret: undefined. When the signer receives this undefined secret, it throws a crypto error.

The Fix

This patch strictly enforces the OAuth 2.0 / OIDC security model for public clients:

  1. Prevents HS256 Signing: Explicitly blocks the code from attempting to sign with client.clientSecret when client.type === "public".
  2. Enforces Asymmetric Signing: Throws a clear, actionable error if a public client is configured without the jwt plugin enabled. Public clients must use RS256 (provided by the JWT plugin) since they cannot securely hold a symmetric secret.

Summary by cubic

Prevents crashes when public OIDC clients request ID tokens. Enforces RS256 via the JWT plugin for public clients and validates clientSecret for HS256.

  • Bug Fixes
    • Block HS256 signing for public clients; require the jwt plugin (RS256).
    • Add clear errors: public clients need jwt; HS256 requires a client_secret.

Written for commit 6bc17dd68a. 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/6712 **Author:** [@GautamBytes](https://github.com/GautamBytes) **Created:** 12/12/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/oidc-public-client-signing` --- ### 📝 Commits (2) - [`fdeaff4`](https://github.com/better-auth/better-auth/commit/fdeaff4a84a1069f49ec18657e20762eb75f9fa1) fix(oidc-provider): prevent crash when signing ID tokens for public clients - [`6bc17dd`](https://github.com/better-auth/better-auth/commit/6bc17dd68a9233d93c5569264b506caa0b1ce28d) added test cases ### 📊 Changes **2 files changed** (+228 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/oidc-provider/index.ts` (+16 -0) 📝 `packages/better-auth/src/plugins/oidc-provider/oidc.test.ts` (+212 -0) </details> ### 📄 Description ## Description Fixes #6651 This PR addresses a runtime crash ("Zero-length key is not supported") that occurs when a **Public Client** (e.g., mobile app, SPA) attempts to obtain an ID Token using the OIDC provider. ### The Issue Currently, the OIDC provider defaults to symmetric signing (`HS256`) using the `clientSecret` if the `jwt` plugin is not explicitly enabled. Public clients (using PKCE) correctly have `clientSecret: undefined`. When the signer receives this undefined secret, it throws a crypto error. ### The Fix This patch strictly enforces the OAuth 2.0 / OIDC security model for public clients: 1. **Prevents HS256 Signing:** Explicitly blocks the code from attempting to sign with `client.clientSecret` when `client.type === "public"`. 2. **Enforces Asymmetric Signing:** Throws a clear, actionable error if a public client is configured without the `jwt` plugin enabled. Public clients *must* use RS256 (provided by the JWT plugin) since they cannot securely hold a symmetric secret. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Prevents crashes when public OIDC clients request ID tokens. Enforces RS256 via the JWT plugin for public clients and validates clientSecret for HS256. - **Bug Fixes** - Block HS256 signing for public clients; require the jwt plugin (RS256). - Add clear errors: public clients need jwt; HS256 requires a client_secret. <sup>Written for commit 6bc17dd68a9233d93c5569264b506caa0b1ce28d. 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-15 21:57:01 -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#23744