question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`withCredentials` flag gets ignored on iOS

See original GitHub issue

Is this a bug report?

Yes

Have you read the Bugs section of the Contributing to React Native Guide?

Yes

Environment

  1. react-native -v: 0.46

Then, specify:

  1. Target Platform: iOS
  2. Development Operating System: macOS
  3. Build tools: Xcode

Description

In react-native@0.44, a flag withCredentials was introduced. In react-native@0.46, the behaviour was unintentionally changed by this commit: 047961fbf77cb012b53978184102e8ca3d00c7ec

withCredentials = true translates to HTTPShouldHandleCookies = YES in native code. After the commit that I linked above, the Cookie header gets set explicitly, which overrides any behaviour set by HTTPShouldHandleCookies.

Steps to Reproduce

Make a fetch request with the flag withCredentials: true.

Expected Behavior

The flag gets respected. The cookie header only gets set explicitly if withCredentials = false

Actual Behavior

The flag gets overridden.

Reproducible Demo

Hard to make a demo, but the bug can be proven with the Apple documentation:

If your app sets the Cookie header on an NSMutableURLRequest object, then this method has no effect, and the cookie data you set in the header overrides all cookies from the cookie store.

Here you can see that HTTPShouldHandleCookies is being set based on the withCredentials flag.

Here you can see that the Cookie header is being set explicitly, which takes precedence over HTTPShouldHandleCookies.

Related issues

  • withCredentials flag in XHRs should default to “true” #14063

cc

@clozr

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:11
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
panunucommented, Sep 28, 2017

Any news or progress on this? 😃

1reaction
jamesreggiocommented, Jul 26, 2017

I raised some concerns in https://github.com/facebook/react-native/pull/14931#issuecomment-318149698, which contains the proposed fix.

I’m not sure if I’m clear on precisely what behavior you’re expecting. Specifically, when you use withCredentials: true are you finding that the value of the Cookie header in the resulting request is missing some cookies? Or is it that Set-Cookie response headers aren’t being respected.

I expect that the problem may be that cookies are missing, because the changes in 047961fbf77cb012b53978184102e8ca3d00c7ec switched to a different cookie jar. Understandably, this would be bad for existing users, who could potentially be logged out through the loss of the cookies that were set before that change. However, I’d like clarification from those of you who are affected, since I’m afraid #14931 may have the wrong fix.

Read more comments on GitHub >

github_iconTop Results From Across the Web

XMLHttpRequest.withCredentials - Web APIs | MDN
Setting withCredentials has no effect on same-origin requests. In addition, this flag is also used to indicate when cookies are to be ignored...
Read more >
Angular is not sending the Cookie received in Set-Cookie ...
The cookie I was sending had secureCookie flag on. ... as calling same api from Angular code, set-cookie was getting skipped or ignored....
Read more >
iOS App "To-Do" Flag and Count Incorrect - Canvas Community
I wish I could ignore the flag, but what if the erroneous things are cleared and new things get added? I can't take...
Read more >
XMLHttpRequest.withCredentials - Web APIs
Setting withCredentials has no effect on same-site requests. In addition, this flag is also used to indicate when cookies are to be ignored...
Read more >
App Search Programming Guide: Support Universal Links
When you support universal links, iOS users can tap a link to your website and get seamlessly redirected to your installed app without...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found