[PR #6472] [MERGED] fix(oauth-proxy): point provider requests to production and fix cookie handling in non-HTTPS environments #6690

Closed
opened 2026-03-13 13:08:18 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6472
Author: @bytaesu
Created: 12/2/2025
Status: Merged
Merged: 12/27/2025
Merged by: @Bekacru

Base: canaryHead: 2025-12-02/fix/oauth-proxy-cookie-handling


📝 Commits (10+)

  • 2517fb0 add utils and constants for secure cookie prefixes
  • adddfa2 point redirect_uri to production and improve cookie handling on non-secure contexts
  • 1b7a5a7 test: add test cases for stripSecureCookiePrefix util
  • ff7e764 Merge branch 'canary' into 2025-12-02/fix/oauth-proxy-cookie-handling
  • e80fc06 Merge branch 'canary' into 2025-12-02/fix/oauth-proxy-cookie-handling
  • 1100bd9 Merge branch 'canary' into 2025-12-02/fix/oauth-proxy-cookie-handling
  • 1ed9773 fix: imports
  • 1f0a7b0 fix: prevent trailing double slash
  • dcb1a27 fix: prevent decodeURI fail
  • 857035b Merge branch 'canary' into 2025-12-02/fix/oauth-proxy-cookie-handling

📊 Changes

5 files changed (+117 additions, -17 deletions)

View changed files

📝 packages/better-auth/src/cookies/cookie-utils.ts (+16 -0)
📝 packages/better-auth/src/cookies/cookies.test.ts (+58 -1)
📝 packages/better-auth/src/cookies/index.ts (+5 -4)
📝 packages/better-auth/src/plugins/oauth-proxy/index.ts (+30 -12)
📝 packages/better-auth/src/plugins/oauth-proxy/utils.ts (+8 -0)

📄 Description

This PR includes the following changes:

  • Centralize secure cookie prefix handling with constants and utilities.
  • Make OAuth provider requests originate from the production server (will be proxied later).
  • Ensure secure cookie prefixes are not applied in non-HTTPS environments (e.g. localhost).

Summary by cubic

Routes OAuth provider redirects to production and fixes cookie behavior in non-HTTPS environments by standardizing secure prefixes and stripping them when needed. Prevents localhost issues with __Secure/__Host cookies and ensures provider callbacks target production.

  • Bug Fixes

    • Strip __Secure- and __Host- prefixes in non-HTTPS contexts and decode cookie values before setting.
    • Set redirect_uri to production when productionURL is provided and prevent double slashes in error/callback URLs.
  • Refactors

    • Added SECURE_COOKIE_PREFIX/HOST_COOKIE_PREFIX constants and a stripSecureCookiePrefix utility; applied across cookie getters and cache.

Written for commit ad83c84361. 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/6472 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 12/2/2025 **Status:** ✅ Merged **Merged:** 12/27/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `2025-12-02/fix/oauth-proxy-cookie-handling` --- ### 📝 Commits (10+) - [`2517fb0`](https://github.com/better-auth/better-auth/commit/2517fb0fe975d0cdaa75a95e93a8787c920b9365) add utils and constants for secure cookie prefixes - [`adddfa2`](https://github.com/better-auth/better-auth/commit/adddfa20afa5c470ecc0f3b54e4fd3bc05d1de96) point redirect_uri to production and improve cookie handling on non-secure contexts - [`1b7a5a7`](https://github.com/better-auth/better-auth/commit/1b7a5a7075f12da8cd273c957d3d1868f56cac18) test: add test cases for stripSecureCookiePrefix util - [`ff7e764`](https://github.com/better-auth/better-auth/commit/ff7e76409b53ab5cf100b0f1af245e2dd9c634b3) Merge branch 'canary' into 2025-12-02/fix/oauth-proxy-cookie-handling - [`e80fc06`](https://github.com/better-auth/better-auth/commit/e80fc06cba41151c602644821298cba09ad680d6) Merge branch 'canary' into 2025-12-02/fix/oauth-proxy-cookie-handling - [`1100bd9`](https://github.com/better-auth/better-auth/commit/1100bd9eefd74d6827e7ec7faef3571caea5830c) Merge branch 'canary' into 2025-12-02/fix/oauth-proxy-cookie-handling - [`1ed9773`](https://github.com/better-auth/better-auth/commit/1ed9773aed469b6f8e4312742144dcf6c00e2a30) fix: imports - [`1f0a7b0`](https://github.com/better-auth/better-auth/commit/1f0a7b0b46fce66d40d3fe66f573bf4ee18f53c2) fix: prevent trailing double slash - [`dcb1a27`](https://github.com/better-auth/better-auth/commit/dcb1a27b743aaac22e6cc377c9b2887a1e4c35e8) fix: prevent decodeURI fail - [`857035b`](https://github.com/better-auth/better-auth/commit/857035be010bdb7bdca8fcd3ea722f3ada5df7ab) Merge branch 'canary' into 2025-12-02/fix/oauth-proxy-cookie-handling ### 📊 Changes **5 files changed** (+117 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/cookies/cookie-utils.ts` (+16 -0) 📝 `packages/better-auth/src/cookies/cookies.test.ts` (+58 -1) 📝 `packages/better-auth/src/cookies/index.ts` (+5 -4) 📝 `packages/better-auth/src/plugins/oauth-proxy/index.ts` (+30 -12) 📝 `packages/better-auth/src/plugins/oauth-proxy/utils.ts` (+8 -0) </details> ### 📄 Description This PR includes the following changes: - Centralize secure cookie prefix handling with constants and utilities. - Make OAuth provider requests originate from the production server (will be proxied later). - Ensure secure cookie prefixes are not applied in non-HTTPS environments (e.g. localhost). <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Routes OAuth provider redirects to production and fixes cookie behavior in non-HTTPS environments by standardizing secure prefixes and stripping them when needed. Prevents localhost issues with __Secure/__Host cookies and ensures provider callbacks target production. - **Bug Fixes** - Strip __Secure- and __Host- prefixes in non-HTTPS contexts and decode cookie values before setting. - Set redirect_uri to production when productionURL is provided and prevent double slashes in error/callback URLs. - **Refactors** - Added SECURE_COOKIE_PREFIX/HOST_COOKIE_PREFIX constants and a stripSecureCookiePrefix utility; applied across cookie getters and cache. <sup>Written for commit ad83c8436145c4872b95d86df452aa2912310ed7. 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-03-13 13:08:18 -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#6690