[PR #7069] [MERGED] fix(expo): skip cookie/expo-origin headers for ID token requests #15302

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7069
Author: @kimchi-developer
Created: 12/30/2025
Status: Merged
Merged: 2/28/2026
Merged by: @Bekacru

Base: canaryHead: fix/expo-idtoken-skip-cookie


📝 Commits (2)

  • 3fb499d fix(expo): skip cookie/expo-origin headers for ID token requests
  • 8bc2aa4 Merge branch 'canary' into fix/expo-idtoken-skip-cookie

📊 Changes

2 files changed (+80 additions, -2 deletions)

View changed files

📝 packages/expo/src/client.ts (+19 -2)
📝 packages/expo/test/expo.test.ts (+61 -0)

📄 Description

Summary

ID token flow (native sign-in with Google/Apple) doesn't need cookie-based authentication. The ID token itself is cryptographically signed by the provider and validated server-side.

Previously, the expo client would always send cookie and expo-origin headers, which triggered unnecessary origin checks that fail for custom URL schemes (e.g., modu-dev://, myapp://).

Problem

When using ID token authentication with a custom URL scheme:

await authClient.signIn.social({
    provider: 'google',
    idToken: { token: idToken },
});

The expo client sends:

  • cookie header (even for stateless ID token auth)
  • expo-origin: modu-dev:// header

The server then:

  1. Copies expo-origin to origin header
  2. Runs origin check because cookie header exists
  3. Fails because modu-dev:// is not in trustedOrigins
ERROR [Better Auth]: Invalid origin: modu-dev://

Solution

Detect ID token requests by checking for options.body?.idToken and skip adding cookie/expo-origin headers for these requests.

const isIdTokenRequest = options.body?.idToken !== undefined;

if (isIdTokenRequest) {
    // Only add x-skip-oauth-proxy, no cookie/expo-origin
} else {
    // Add cookie/expo-origin for browser OAuth flow
}

Why This Makes Sense

Flow Needs Cookies Needs Origin Check
Browser OAuth Yes (session management) Yes (CSRF protection)
ID Token No (stateless, token is proof) No (token is cryptographically signed)

Test Plan

  • Added test: "should not send cookie or expo-origin headers for ID token requests"
  • Existing tests pass

Summary by cubic

Skip sending cookie and expo-origin headers on Expo ID token requests to prevent origin check failures with custom URL schemes. Native Google/Apple sign-in now works without trusted origin setup.

  • Bug Fixes
    • Detect ID token requests and omit cookie/expo-origin; still set x-skip-oauth-proxy.
    • Preserve existing behavior for browser OAuth flows.
    • Added test to confirm no cookie/expo-origin/origin headers are sent for ID token requests.

Written for commit 8bc2aa4fc4. 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/7069 **Author:** [@kimchi-developer](https://github.com/kimchi-developer) **Created:** 12/30/2025 **Status:** ✅ Merged **Merged:** 2/28/2026 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/expo-idtoken-skip-cookie` --- ### 📝 Commits (2) - [`3fb499d`](https://github.com/better-auth/better-auth/commit/3fb499d43d2ed0fb631665994ae826b02301f603) fix(expo): skip cookie/expo-origin headers for ID token requests - [`8bc2aa4`](https://github.com/better-auth/better-auth/commit/8bc2aa4fc484035ab5b1d362ddfbe9690edcae38) Merge branch 'canary' into fix/expo-idtoken-skip-cookie ### 📊 Changes **2 files changed** (+80 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/expo/src/client.ts` (+19 -2) 📝 `packages/expo/test/expo.test.ts` (+61 -0) </details> ### 📄 Description ## Summary ID token flow (native sign-in with Google/Apple) doesn't need cookie-based authentication. The ID token itself is cryptographically signed by the provider and validated server-side. Previously, the expo client would **always** send `cookie` and `expo-origin` headers, which triggered unnecessary origin checks that fail for custom URL schemes (e.g., `modu-dev://`, `myapp://`). ## Problem When using ID token authentication with a custom URL scheme: ```typescript await authClient.signIn.social({ provider: 'google', idToken: { token: idToken }, }); ``` The expo client sends: - `cookie` header (even for stateless ID token auth) - `expo-origin: modu-dev://` header The server then: 1. Copies `expo-origin` to `origin` header 2. Runs origin check because `cookie` header exists 3. Fails because `modu-dev://` is not in `trustedOrigins` ``` ERROR [Better Auth]: Invalid origin: modu-dev:// ``` ## Solution Detect ID token requests by checking for `options.body?.idToken` and skip adding `cookie`/`expo-origin` headers for these requests. ```typescript const isIdTokenRequest = options.body?.idToken !== undefined; if (isIdTokenRequest) { // Only add x-skip-oauth-proxy, no cookie/expo-origin } else { // Add cookie/expo-origin for browser OAuth flow } ``` ## Why This Makes Sense | Flow | Needs Cookies | Needs Origin Check | |------|---------------|-------------------| | Browser OAuth | ✅ Yes (session management) | ✅ Yes (CSRF protection) | | ID Token | ❌ No (stateless, token is proof) | ❌ No (token is cryptographically signed) | ## Test Plan - [x] Added test: "should not send cookie or expo-origin headers for ID token requests" - [x] Existing tests pass <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Skip sending cookie and expo-origin headers on Expo ID token requests to prevent origin check failures with custom URL schemes. Native Google/Apple sign-in now works without trusted origin setup. - **Bug Fixes** - Detect ID token requests and omit cookie/expo-origin; still set x-skip-oauth-proxy. - Preserve existing behavior for browser OAuth flows. - Added test to confirm no cookie/expo-origin/origin headers are sent for ID token requests. <sup>Written for commit 8bc2aa4fc484035ab5b1d362ddfbe9690edcae38. 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-13 09:57:12 -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#15302