-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
withCredentials flag in XHRs should default to "true" #14063
Comments
According to the commit description, the reason for this breaking change is to be
This doesn't make much sense to me. These are native apps. Native apps don't have cross-site concerns. The JS bundle is not served from a domain like the web. The security model for native mobile apps has been established a long time ago. The standard native API's for making HTTP requests in iOS and Android send cookies by default. Changing this behavior to conform to websites just because we're using JavaScript is strange. In addition, there's a big problem with the override mechanism. This is a breaking change, and now we have apps in production that we cannot release due to this change. The override mechanism according to the commit is:
This makes the assumption that we can control the parameters for every request our app makes. Consider that we're using a 3rd party GraphQL client library that makes the |
Summary: Corresponding Android PR: #12276 Respect the withCredentials XMLHttpRequest flag for sending cookies with requests. This can reduce payload sizes where large cookies are set for domains. This should fix #5347. This is a breaking change because it alters the default behavior of XHR. Prior to this change, XHR would send cookies by default. After this change, by default, XHR does not send cookies which is consistent with the default behavior of XHR on web for cross-site requests. Developers can restore the previous behavior by passing `true` for XHR's `withCredentials` argument. **Test plan (required)** Verified in a test app that XHR works properly when specifying `withCredentials` as `true`, `false`, and `undefined`. Also, my team uses this change in our app. Adam Comella Microsoft Corp. Closes #12275 Differential Revision: D4673644 Pulled By: mkonicek fbshipit-source-id: 2fd8f536d02fb39d872eb849584c5c4f7e7698c5
I'm sorry that my commit is causing issues for you.
Which Android API are you referring to? I think there are several questions to think about here: 1. What should RN's
|
It's time to follow semver :) |
We also faced with this problem, but fortunately, we have direct access to all |
This broke our app too. The original fix looks like it conflicts with: https://github.com/github/fetch/blob/08602ff819f4c41e9d9e9c2c31bfc853b1bb5bf2/fetch.js#L448-L450 It seems to me there a lot of places which sets |
@vafada What places are you referring to? I believe the place you linked to in an implementation of |
Sorry, I just didn't understand the code well enough: I was doing:
when I should be doing:
|
Also, what about |
I personally agree with @rigdern, cookies should be disabled by default. We simply have to adopt new policy. Peace. |
Apologies for not taking this under more careful consideration when reviewing the pull request! I thought this would be a strict win because it brings the two platforms in alignment, but as @talkol points out, it now conflicts with the behavior of the native networking libraries. At this point I think it may be worthwhile to keep the new behavior, because we've already switched it, it matches the behavior of JS There are some tradeoffs here so I'd like to run a quick community poll for those paying attention to this issue. Please vote within the next 24 hours: Vote Here!Please "thumbs-up" this post if you want a mechanism to change the default. But we will keep the new behavior that was introduced in
|
Ok, its only been an hour and we've got pretty clear signal: 13 votes to revert to the old credentials default, and 1 vote to keep the consistent behavior with override mechanism. I'll let the vote keep going for the next day, but it sounds like we should go back to the old default. |
So current plan is to undo the breaking change. In long term, we probably want to default to not sending cookies for |
I'll cherry-pick and release new versions today. |
I want to return to the discussion of what is the correct behavior in the long term. I think that the vision behind React Native is to respect the different platforms and not to force web mentality over them. React Native is not web-first. Forcing all platforms to behave like the web is what killed several competing cross-platform frameworks for native developers such as myself. We don't want to make this mistake and alienate native developers. I know that many of the people in this thread are primarily web developers. Please make an effort to understand where the other platforms are coming from. I asked @DanielZlotin to showcase the default behavior in (pure) native mobile in iOS and Android. Hopefully this will explain what we're used to: Example CodeThe example has Objective-C + Java code which uses default native APIs for fetching data: Analysis of the defaults for iOShttps://github.com/wix/react-native-cookie-example/tree/master/ios/CookieExample The default API doesn't require anything special related to cookies. Cookies are stored by default for all domains. Native code has full access to all cookies anyways so it doesn't make sense to limit them. I tried to find the defaults in the code documentation as well:
Analysis of the defaults for Androidhttps://github.com/wix/react-native-cookie-example/tree/master/android/CookieExample Android is more tricky because they chose to base their original HTTP API on the standard Java API. The Java API tries to make zero assumptions on platform and predated mobile, so it's hard to understand the platform state of mind from it. Newer API like okhttp conforms to the same API style. The Java API is a very low level API with very few abstractions. You have to do everything manually, including specify your cookie storage implementation (so it's not tied to a specific one). The fact that you need to specify it IMO does not reflect that cookies are disabled. There are 3 main cookie policies and the default policy is set by I tried to find this also in the code documentation:
The original server policy means that as long as any HTTP server specifies their own domain on the cookies, the cookies are saved and returned. You can see this behavior in the simple example above. My recommendations
What happens if my app behaves differently in the web or as native app on device?I think that's part of the point. If you're specifying a specific behavior, it will be respected. If you're not, you're expecting the defaults to behave correctly. If you're running in a web browser, there's no trust between the user and you and the user should be protected. If the user chose to install you natively and showed intent to have a relationship with you, there's more trust and we can provide a more intimate relationship. In other words, it's not "write once, run anywhere", it's "learn once, write anywhere". |
@talkol Tal, |
@shergin I meant iOS and Android, the first two platforms, should have same defaults. Third platform is web, so if you're targeting your codebase for web (by sharing the same JS implementation) then you'll get the browser defaults naturally which can be different. And any other platforms like native desktop should have their own defaults. |
I see that we are not considering another possible value - |
Just to add the discuss. I have created an app using is this problem related to this issue? I am using |
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:
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. |
Description
react-native 0.44 introduced
withCredentials
flag in XHRs, which, if not specified in everyfetch
request, defaults tofalse
.This change conflicts with the default behavior in native. In the iOS native SDK and the Android native SDK, when making a native HTTP request, cookies are sent by default.
We rarely have agreement between the platforms, but for the last 10 years they both agree on this security model for apps.
This greatly affects projects relying on cookies with their requests.
Additional Information
The text was updated successfully, but these errors were encountered: