[PR #8966] [CLOSED] fix(generic-oauth): encode error params to prevent crash with non-ASCII chars #25233

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8966
Author: @cyphercodes
Created: 4/5/2026
Status: ❌ Closed

Base: main ← Head: fix/encode-oauth-error-params


📝 Commits (1)

  • cf70cec fix(generic-oauth): encode error_description to prevent crash with non-ASCII characters

📊 Changes

1 file changed (+5 additions, -3 deletions)

View changed files

📝 packages/better-auth/src/plugins/generic-oauth/routes.ts (+5 -3)

📄 Description

Description

When OAuth providers return error_description containing non-ASCII characters (e.g., Cyrillic text from Yandex OAuth), the generic-oauth callback handler crashes with a TypeError because the description is interpolated directly into the redirect URL without encoding.

Error

TypeError: Header 'location' has invalid value:
'https://example.com/auth/error?error=unauthorized_client&error_description=Запрещено получать токены...'

Non-ASCII characters in HTTP Location header are invalid per RFC 7230.

Fix

Wrap query parameters with encodeURIComponent() when building the error redirect URL.

Related Issue

Fixes #8954


Summary by cubic

Encode OAuth error query params in the generic-oauth callback to prevent crashes when providers return non-ASCII characters. Ensures valid Location headers and reliable redirects to the error page.

  • Bug Fixes
    • URL-encode error and error_description with encodeURIComponent, and default to oAuth_code_missing/empty when missing, preventing invalid Location headers with non-ASCII text (e.g., Yandex OAuth).

Written for commit cf70cec909. 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/8966 **Author:** [@cyphercodes](https://github.com/cyphercodes) **Created:** 4/5/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/encode-oauth-error-params` --- ### 📝 Commits (1) - [`cf70cec`](https://github.com/better-auth/better-auth/commit/cf70cec909ca32a32c3230f5d873751738283e9a) fix(generic-oauth): encode error_description to prevent crash with non-ASCII characters ### 📊 Changes **1 file changed** (+5 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/generic-oauth/routes.ts` (+5 -3) </details> ### 📄 Description ## Description When OAuth providers return error_description containing non-ASCII characters (e.g., Cyrillic text from Yandex OAuth), the generic-oauth callback handler crashes with a TypeError because the description is interpolated directly into the redirect URL without encoding. ## Error ``` TypeError: Header 'location' has invalid value: 'https://example.com/auth/error?error=unauthorized_client&error_description=Запрещено получать токены...' ``` Non-ASCII characters in HTTP Location header are invalid per RFC 7230. ## Fix Wrap query parameters with `encodeURIComponent()` when building the error redirect URL. ## Related Issue Fixes #8954 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Encode OAuth error query params in the `generic-oauth` callback to prevent crashes when providers return non-ASCII characters. Ensures valid Location headers and reliable redirects to the error page. - **Bug Fixes** - URL-encode `error` and `error_description` with `encodeURIComponent`, and default to `oAuth_code_missing`/empty when missing, preventing invalid Location headers with non-ASCII text (e.g., Yandex OAuth). <sup>Written for commit cf70cec909ca32a32c3230f5d873751738283e9a. 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-15 22:46: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#25233