react-native-cookies / cookies

🍪 Cookie Manager for React Native
MIT License
483 stars 95 forks source link

How I can get http-only and secure cookies on android device #76

Open cody0203 opened 4 years ago

cody0203 commented 4 years ago

Hello guys,

I'm current build a RN app with react-native-webview and @react-native-community/cookies. Now, i need to access all cookies in webview. With some help of @react-native-community/cookies on ios devices, i can get all of this but on android i only get non-secure/non-httpOnly cookies.

Android devices is running on API 28.

Here my code:

  1. Implement webview <WebView ref={webViewRef} source={{uri: 'https://example.com'}} javaScriptEnabled={true} sharedCookiesEnabled={true} thirdPartyCookiesEnabled={true} />
  2. Get cookies useEffect(() => { let getCookies = () => CookieManager.getAll(useWebKit).then((cookies) => { console.log('CookieManager.get =>', cookies); }); if (Platform.OS === 'android') { getCookies = () => CookieManager.get('https://linkedin.com').then((cookies) => { console.log('CookieManager.get =>', cookies); }); } getCookies(); }, []);
marf commented 4 years ago

Hello @cody0203 , have you found a solution?

geroale commented 4 years ago

Same issue here

cody0203 commented 4 years ago

Hello @cody0203 , have you found a solution?

Same issue here

Nah, still stuck in there

roeycohen commented 4 years ago

Hi @cody0203, I'm experiencing a problem where CookieManager.get('https://linkedin.com') get all cookies but all are with httpOnly=false (even though some of them are differently true). Is that the same for you?

cody0203 commented 4 years ago

@roeycohen yes. It get only httpOnly=false on android devices.

roeycohen commented 4 years ago

Hi @cody0203, 10x for answering! Do you know if it means that you can't set httpOnly cookie as well?

Update: setting httpOnly seems to work (at least for android N and above)

cody0203 commented 4 years ago

Hi @cody0203, 10x for answering! Do you know if it means that you can't set httpOnly cookie as well?

Update: setting httpOnly seems to work (at least for android N and above)

Oh i only need to get it.

hengkx commented 4 years ago

ios need get httponly cookie

cody0203 commented 4 years ago

@hengkx Ios still can get httpOnly cookie, try to use CookieManager.getAll(true).then(...).

hengkx commented 4 years ago

@hengkx Ios still can get httpOnly cookie, try to use CookieManager.getAll(true).then(...).

Thanks. The simulator can get. the real machine can't get cookies.

cody0203 commented 4 years ago

Thanks. The simulator can get. the real machine can't get cookies.

Two months ago when i still development my old app, i remember i still can get it in real device. But for now, i can't confirm that, sorry.

marf commented 4 years ago

Hello, we can confirm that with CookieManager.getAll(true).then(...) we can get all cookies in iOS, the problem is that there is no such function in Android we are not able to the all the cookies (even the httpOnly ones) on Android devices. Hope there is a solution for that which can make Android & iOS behave the same.

cody0203 commented 4 years ago

@marf I think this issue become from Android native code, in class CookieManager, not from this library.

marf commented 4 years ago

@marf I think this issue become from Android native code, in class CookieManager, not from this library.

@cody0203 do you think that in android there is no library which allows this or simply we have to fork CookieManager to allow this kind of behavior the same as in iOS?

cody0203 commented 4 years ago

@marf I think this issue become from Android native code, in class CookieManager, not from this library.

@cody0203 do you think that in android there is no library which allows this or simply we have to fork CookieManager to allow this kind of behavior the same as in iOS?

I don't know if any android's library can do it but i have tried to re config CookieManager in android code and nothing happen. In android official docs doesn't mention about this feature too. Sry for my bad English, wish you can understand.

marf commented 4 years ago

@marf I think this issue become from Android native code, in class CookieManager, not from this library.

@cody0203 do you think that in android there is no library which allows this or simply we have to fork CookieManager to allow this kind of behavior the same as in iOS?

I don't know if any android's library can do it but I have tried to re config CookieManager in android code and nothing happens. In android official docs don't mention this feature too. Sry for my bad English, wish you can understand.

I am not an English native speaker too :) The only thing I have found is this answer from StackOverflow:

Get HttpOnly Cookies Android

It suggests using reflection, but it is quite old and a comment said that it does not work, so I am not sure if this may be a solution.

cody0203 commented 4 years ago

@marf I think this issue become from Android native code, in class CookieManager, not from this library.

@cody0203 do you think that in android there is no library which allows this or simply we have to fork CookieManager to allow this kind of behavior the same as in iOS?

I don't know if any android's library can do it but I have tried to re config CookieManager in android code and nothing happens. In android official docs don't mention this feature too. Sry for my bad English, wish you can understand.

I am not an English native speaker too :) The only thing I have found is this answer from StackOverflow:

Get HttpOnly Cookies Android

It suggests using reflection, but it is quite old and a comment said that it does not work, so I am not sure if this may be a solution.

I tried and it does not work :)

rizkiandrianto commented 3 years ago

@marf I think this issue become from Android native code, in class CookieManager, not from this library.

@cody0203 do you think that in android there is no library which allows this or simply we have to fork CookieManager to allow this kind of behavior the same as in iOS?

I don't know if any android's library can do it but I have tried to re config CookieManager in android code and nothing happens. In android official docs don't mention this feature too. Sry for my bad English, wish you can understand.

I am not an English native speaker too :) The only thing I have found is this answer from StackOverflow: Get HttpOnly Cookies Android It suggests using reflection, but it is quite old and a comment said that it does not work, so I am not sure if this may be a solution.

I tried and it does not work :)

Maybe only works for old android version?

cody0203 commented 3 years ago

@marf I think this issue become from Android native code, in class CookieManager, not from this library.

@cody0203 do you think that in android there is no library which allows this or simply we have to fork CookieManager to allow this kind of behavior the same as in iOS?

I don't know if any android's library can do it but I have tried to re config CookieManager in android code and nothing happens. In android official docs don't mention this feature too. Sry for my bad English, wish you can understand.

I am not an English native speaker too :) The only thing I have found is this answer from StackOverflow: Get HttpOnly Cookies Android It suggests using reflection, but it is quite old and a comment said that it does not work, so I am not sure if this may be a solution.

I tried and it does not work :)

Maybe only works for old android version?

Not sure but if that true, it's useless :)

shmkane commented 2 years ago

Has anyone found a solution?

liaoliao666 commented 1 year ago

I've also been stuck on this issue recently. and how to get http-only cookie from response headers

guofeng007 commented 1 year ago

just connect to the webview cookie with sqlite database and read all the data from DB

IshanArya commented 1 year ago

just connect to the webview cookie with sqlite database and read all the data from DB

what does that mean???

cdaringe commented 11 months ago

clients shouldnt be able to head http-only cookies--that's quite literally the entire purpose of http-only cookies--preventing client side access.

AlexRixten commented 5 months ago

hi, everyone) you can try to do this, it works for me, but it is for android... CookieManager.get('domain', true).then(...)