[PR #6019] [CLOSED] Fix: hex string expected, got unpadded hex of length 253 #14634

Closed
opened 2026-04-13 09:33:19 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6019
Author: @firdausai
Created: 11/16/2025
Status: Closed

Base: canaryHead: fix/oauth-encryption


📝 Commits (1)

  • e293957 add 'enc:' to differentiate between encrypted and non-encrypted key

📊 Changes

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

View changed files

📝 packages/better-auth/src/oauth2/utils.ts (+5 -4)

📄 Description

Propose solution to bug reported in #6018

This PR fixes a bug where toggling encryptOAuthTokens from false to true causes a "hex string expected, got unpadded hex of length 253" error when refreshing expired tokens. The issue occurred because decryptOAuthToken attempted to decrypt plain text tokens that were stored before encryption was enabled. The fix adds a prefix-based check (enc:) to distinguish encrypted tokens from plain text ones. Encrypted tokens are now prefixed with enc: when stored with setTokenUtil, and decryptOAuthToken only attempts decryption if the prefix is present.


Summary by cubic

Prefix encrypted OAuth tokens with 'enc:' and decrypt only when the prefix is present. Prevents errors when handling plaintext or mixed tokens.

  • Bug Fixes

    • Stops decryption attempts on plaintext tokens, avoiding failures when encryption is disabled or tokens vary.
  • Migration

    • setTokenUtil is now async; update callers to await its result.

Written for commit e293957d65. 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/6019 **Author:** [@firdausai](https://github.com/firdausai) **Created:** 11/16/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/oauth-encryption` --- ### 📝 Commits (1) - [`e293957`](https://github.com/better-auth/better-auth/commit/e293957d651494ad554bd79fab7d735b1accbd14) add 'enc:' to differentiate between encrypted and non-encrypted key ### 📊 Changes **1 file changed** (+5 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/oauth2/utils.ts` (+5 -4) </details> ### 📄 Description Propose solution to bug reported in [#6018](https://github.com/better-auth/better-auth/issues/6018) This PR fixes a bug where toggling `encryptOAuthTokens` from `false` to `true` causes a `"hex string expected, got unpadded hex of length 253"` error when refreshing expired tokens. The issue occurred because `decryptOAuthToken` attempted to decrypt plain text tokens that were stored before encryption was enabled. The fix adds a prefix-based check (`enc:`) to distinguish encrypted tokens from plain text ones. Encrypted tokens are now prefixed with `enc:` when stored with setTokenUtil, and `decryptOAuthToken` only attempts decryption if the prefix is present. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Prefix encrypted OAuth tokens with 'enc:' and decrypt only when the prefix is present. Prevents errors when handling plaintext or mixed tokens. - **Bug Fixes** - Stops decryption attempts on plaintext tokens, avoiding failures when encryption is disabled or tokens vary. - **Migration** - setTokenUtil is now async; update callers to await its result. <sup>Written for commit e293957d651494ad554bd79fab7d735b1accbd14. 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-13 09:33:19 -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#14634