Mobile

Android WebView OAuth redirect loses session cookies when using Custom Tabs and 302 cross-subdomain redirect

Environment

Environment

Android 12/13 devices from multiple OEMs, app implemented in Kotlin using AndroidX Browser custom tabs for OAuth flow; app server issues initial auth URL at auth.example.com which redirects (302) to login.example.com then back to app callback scheme. Cookies are host-scoped to .example.com, Secure, HttpOnly, SameSite=Lax. Embedded WebView flows (WebView-based auth) do not show the problem; only Custom Tab flow loses cookies mid-flow.

Symptoms

Symptoms

Users are intermittently required to re-login during OAuth flow: after submitting credentials at login.example.com the next redirected request arrives at auth.example.com without the session cookie, resulting in a fresh login screen. This occurs in roughly 5–15% of attempts and is more common when autofill or password managers invoke or when multiple tabs are open.

Observations

Observations

Reproducible on several devices; when reproducing with a proxy (mitmproxy) the browser initial request carries Cookie, but the redirect response's subsequent GET sometimes lacks Cookie header. The issue correlates with the presence of an intermediate 302 cross-subdomain redirect (auth.example.com → login.example.com → auth.example.com). When SameSite set to None cookies behavior changes: losses become rarer but some clients still lose cookies. Using in-app WebView (not Custom Tab) removes the problem. Android logs show Custom Tabs process occasionally spawning new warm browser process which may not share cookie jar immediately.

Already attempted

Already attempted

Switched to launching Chrome custom tab vs device default browser — behavior similar; tested adding explicit cookie domain and path settings; tried changing SameSite to None and Secure flag preserved — partially reduced failures but did not eliminate. Implemented OAuth flow to avoid one of the redirects (direct link) and saw elimination of the issue during tests. Did not change app package signing or deep link handling.

Question

Question

Why are cookies lost in the Custom Tab OAuth flow across a 302 cross-subdomain redirect, and what are the recommended ways to reliably preserve authentication state for mobile OAuth without degrading security (e.g., avoid SameSite=None unless necessary)?

COMMUNITY RESPONSES

Verified community troubleshooting

0 replies

No answers yet..

Showing 0 of 0 community responses
AI DIAGNOSTICS

Incident analysis

Updated 1mo ago• Trouble ID

Most likely causes

Custom Tab/browser process swap across redirect leads to cookie jar not being propagated immediately between renderer processes, so the redirected request misses cookie header 70%
Browser privacy heuristics or SameSite handling treat the redirect as cross-site navigation and suppress cookies intermittently (especially with Lax), causing losses in some flows 50%
Inconsistent domain scoping for cookies (e.g., missing leading dot for .example.com) leading some clients to not attach cookies on subdomain-to-subdomain redirects 30%

Summary

Custom Tabs are implemented by a separate browser process that may not expose the same cookie jar semantics as an in-app WebView and depends on the system browser to manage cookies. Cross-subdomain 302 sequences can interact with SameSite and browser optimizations (dedicated cookie stores for separate renderer processes, process swapping, or privacy heuristics) and cause cookies not to be sent on the subsequent redirected request. The fact that removing a redirect eliminates the issue strongly suggests the redirect sequence and process-host switching in Chrome/Custom Tabs are the triggers. Setting SameSite=None reduces trigger conditions but may have security implications.

Suggested Fixes

Diagnostic step 1
Remove intermediate redirects in the OAuth flow so the browser stays on the same origin chain for the minimal number of hops — redirect elimination is reversible and the most reliable fix observed in testing.
Diagnostic step 2
If redirects are unavoidable, consider using stateful server-side session tokens passed via the query string for intermediate hops (short-lived one-time tokens) instead of relying solely on cookies, and ensure these tokens are single-use and expire quickly to avoid security issues.
Diagnostic step 3
As a diagnostic, set SameSite=None on the cookie (Secure required) and test widely; if this resolves the issue fully, weigh the security trade-offs and consider tightening other controls (CSRF tokens, origin checks) before rolling out. Document this change and revert if unacceptable.