Android WebView OAuth redirect loses session cookies when using Custom Tabs and 302 cross-subdomain redirect
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
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
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
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
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)?
Verified community troubleshooting
No answers yet..