Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch API on Android doesn't respect credentials: omit #12956

Closed
Ashoat opened this issue Mar 15, 2017 · 10 comments
Closed

fetch API on Android doesn't respect credentials: omit #12956

Ashoat opened this issue Mar 15, 2017 · 10 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@Ashoat
Copy link
Contributor

Ashoat commented Mar 15, 2017

Description

If Android's native networking library detects valid cookies for a particular network request it will always tack those cookies onto the request, even if credentials: "omit" is passed to the fetch API.

This problem has been reported multiple times in #1274, which is an related issue that has been closed. I wanted to create a new issue to track it.

This problem makes it very difficult to fully encapsulate cookie logic within Javascript, and necessitates interacting directly with native cookie storage with something like react-native-cookies. This is unfortunate, as there is no particular reason that cookies ought to be handled natively, and outside of this problem it is possible to handle cookies entirely in Javascript.

Reproduction

  1. First, get a cookie set on the client by hitting a server endpoint that returns a Set-Cookie header.
  2. On Android,
await fetch(
  credentials: 'omit',
  ...
);
  1. Add some logging code on the server to see if a Cookie header is set by client. Confirm that this is happening.

Solution

React Native on Android should respect the credentials: 'omit' option.

Additional Information

  • React Native version: 42
  • Platform: Android only
  • Operating System: macOS
@jtmarmon
Copy link

as far as I can tell this is an issue on iOS as well

@vijayst
Copy link

vijayst commented Apr 5, 2017

I am facing the same issue. Using credentials: 'omit' on Android fetch does not work.

@jtmarmon
Copy link

jtmarmon commented Apr 5, 2017

for anyone looking for a workaround, since i didn't need cookies at all, i just cleared cookies before each request using https://github.com/joeferraro/react-native-cookies

@yabeow
Copy link

yabeow commented May 27, 2017

There is a commit that supposed to be solved this issue, but it not working for me. Any idea?
JakeChampion/fetch@c389ccd

@hramos hramos added the Icebox label Jul 31, 2017
@hramos
Copy link
Contributor

hramos commented Jul 31, 2017

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

@hramos hramos closed this as completed Jul 31, 2017
@kadzier
Copy link

kadzier commented Aug 23, 2017

Just ran into this exact issue. Currently using https://www.npmjs.com/package/react-native-cookie as a workaround; simply clearing the cookies before each request.

@GetSource1234
Copy link

Spotted the same issue, would be great to have a proper fix.

@2DKot
Copy link

2DKot commented May 8, 2018

If you are using Expo, you can't run react-native link to use react-native-cookie.
But you can clear cookies this way:

var RCTNetworking = require('RCTNetworking')
function clearCookies () {
  RCTNetworking.clearCookies((cleared) => {
    console.log('Cookies cleared, had cookies=' + cleared.toString())
  })
}

Maybe it will help someone.

@winterbe
Copy link
Contributor

After upgrading to the latest RN version, I've faced a similar issue regarding authentication cookies. Authentication worked fine on first login, but failed after reloading the iOS simulator. My guess is that RN fetch reuses an old cookie after reload? However clearing cookies before performing initial login fixes the issue. Solution from @2DKot works for me. Thanks for that! 👍

It would be great to have more debug information at hand in DevTools network panel. Both cookies and 302 redirects are really hard to track compared to browser web apps. You can just guess what's going on or use external tools. In my case Login was successful and sends 302 to another page which then redirects to login endpoint again because of wrong cookie sent. 💩

@nicksyndicate
Copy link

would be great if it will be worked as in specification

@facebook facebook locked as resolved and limited conversation to collaborators Jul 31, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests