joeferraro / react-native-cookies

Cookie manager for React Native
MIT License
788 stars 314 forks source link

Android: Syncing Cookies with Webview? #79

Closed dahjelle closed 6 years ago

dahjelle commented 6 years ago

I have a React Native app with a WebView. I log in to the web view, and then was hoping I could see all the cookies that the WebView uses by something like:

CookieManager.get(BASE_URL).then(console.log.bind(console, 'cookies'));

But I'm only getting a subset of the cookies that I think must be in the WebView. (i.e. the web app requires 3 or 4 cookies for authentication, and has them when I look in a desktop browser)

I'm at a loss as to why this might be happening. Does the WebView and cookieHandler only sync periodically? Does Android only allow access to, say httpOnly cookies (though that doesn't appear to be what is happening here)? It should support sub-domains? (None of these appear to be the issue as far as I can tell…) Thoughts?

I added a System.out.println to CookieManagerModule.java, in the get method, and it appears that the Cookie information that is coming from React Native isn't complete, either.


I tried to add some logging to ForwardingCookieHandler.java, but I haven't had any luck getting them to appear. I'm guessing that React Native isn't getting recompiled for some reason…I'm happy to dig into this a bit if someone has a pointer or two. :-D I'm mostly a JS dev so it takes a bit more work to understand what Java is doing.

dahjelle commented 6 years ago

I have verified that the other cookies are in the WebView using Chrome's remote debugger.

dahjelle commented 6 years ago

To put some details on my previous comment, here's what Chrome's remote debugger shows me:

untitled

Whereas this code

CookieManager.get('https://david-rubix.iconcmo.com/').then(
  console.log.bind(console, 'cookies')
);

gives me

untitled 2

dahjelle commented 6 years ago

Hmm…I turned off the SameSite attribute server-side, and then I had access to all the cookies. This is apparently not an issue of either react-native-cookies or even react-native, but looks to be an issue of the Android WebView, at least according to this StackOverflow post.

joeferraro commented 6 years ago

thanks for this analysis @dahjelle

dahjelle commented 6 years ago

You bet!

For whatever it is worth, I posted a couple bug reports about this issue:

Do you think, @joeferraro, it'd be worth adding a note to the docs about this issue?