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

Make fetch() use "same-origin" credentials by default #585

Merged
merged 1 commit into from Apr 20, 2018

Conversation

@annevk
Copy link
Member

@annevk annevk commented Aug 25, 2017

Most features in the platform have this default and not having this default causes multiple connections in contemporary implementations. It also causes confusion as switching from XMLHttpRequest to fetch() is not as seamless as it could be.

Making this change will also make it easier for <script type=module> to have this default as per discussion in whatwg/html#2557.


Preview | Diff

Most features in the platform have this default and not having this default causes multiple connections in contemporary implementations. It also causes confusion as switching from XMLHttpRequest to fetch() is not as seamless as it could be.

Making this change will also make it easier for <script type=module> to have this default as per discussion in whatwg/html#2557.
@Munter
Copy link

@Munter Munter commented Aug 25, 2017

Even though I have followed the fetch spec development and implementation and have read multiple blog posts on how to use it, I still got tripped up by forgetting to manually add credentials on certain same-origin fetch-calls. +1 from me on this change

@tyoshino
Copy link
Member

@tyoshino tyoshino commented Aug 25, 2017

I agree that this is a more reasonable default, but also much concerned with possible break of existing apps, though your guess at whatwg/html#2557 (comment) sounds correct.

Let me cc interop leads: @RByers @foolip

@jakearchibald
Copy link
Collaborator

@jakearchibald jakearchibald commented Aug 25, 2017

I've reached out to devs on Twitter. Response is almost entirely positive.

One exception: https://twitter.com/rsjanabasis/status/901012433615020033, and I believe they're going to give us details.

@tyoshino
Copy link
Member

@tyoshino tyoshino commented Aug 25, 2017

Thanks Jake for checking. It's good that it's supported. And, yeah, that looks really one example of the concern.

@foolip
Copy link
Member

@foolip foolip commented Aug 25, 2017

IIUC, changing the default from "omit" to "same-origin" can only mean that credentials are sometimes sent when they otherwise would not be. For resources where it makes a difference at all, it seems rather unusual that the no-credentials response is the one that you want, but that the with-credentials response is some broken/unexpected resource. Certainly possible to create, and certain to appear in the wild given enough time, but are there cases we should worry about?

Overall, the compat risk here seems very low.

@wanderview
Copy link
Member

@wanderview wanderview commented Aug 25, 2017

If we are going to do this it would be nice to try to coordinate shipping the change around the same time.

@annevk
Copy link
Member Author

@annevk annevk commented Aug 28, 2017

Okay, I'll file four implementation bugs. My thinking is that we can update the tests as part of changing the implementation. Easiest to discover all the tests that need changing that way. Is that okay or should I try and prepare test updates?

@foolip
Copy link
Member

@foolip foolip commented Aug 28, 2017

That seems like a good idea where testing without an implementation is error-prone, just leave an open "missing tests" issue and point to it from the impl bugs.

@annevk
Copy link
Member Author

@annevk annevk commented Aug 28, 2017

I was thinking I'd just leave this open until we have a patch or two and no objections.

@foolip
Copy link
Member

@foolip foolip commented Aug 28, 2017

Yeah, that works too. If we have a buildup of "awaiting implementation" issues I guess labels can alleviate that.

@tyoshino
Copy link
Member

@tyoshino tyoshino commented Aug 29, 2017

Thanks, Philip. I'd like to wait and hear the details of what Foggy said in the tweet quoted in #585 (comment). But except for that, I share your analysis basically.

@rsjanabasis
Copy link

@rsjanabasis rsjanabasis commented Aug 30, 2017

I want to make sure that we can block sending credentials by appropriately filtering the request.

For example, if we shadow "fetch" with safe_fetch:
function safe_fetch(url, init) { return fetch(arguments[0], { credentials: 'omit' } ); }
then this will always block sending credentials in every browser, correct?

@tyoshino
Copy link
Member

@tyoshino tyoshino commented Aug 30, 2017

function safe_fetch(url, init) { return fetch(arguments[0], { credentials: 'omit' } ); }
then this will always block sending credentials in every browser, correct?

Right. The topic is about changing the default which is used when the credentials parameter is not specified. You can still explicitly specify the credentials parameter with the value omit as you did to prevent credentials from being sent.

(Your example doesn't inherit values from init. Maybe you want to override credentials but inherit the other values from init.)

@annevk
Copy link
Member Author

@annevk annevk commented Aug 30, 2017

I'd write safe_fetch as:

function safe_fetch(input, init) {
  const tempRequest = new Request(input, init);
  return fetch(tempRequest, { credentials: "omit" });
}
@annevk
Copy link
Member Author

@annevk annevk commented Sep 1, 2017

Is there anything remaining that would block this from being implemented? I'd like this to be done so we can align JavaScript modules with this default and avoid a ton of confusion there.

@rsjanabasis
Copy link

@rsjanabasis rsjanabasis commented Sep 2, 2017

@tyoshino
Copy link
Member

@tyoshino tyoshino commented Sep 13, 2017

Thanks Foggy. So, I'm fine with the plan now.

@annevk
Copy link
Member Author

@annevk annevk commented Sep 13, 2017

Okay, I'll merge this as soon as one of the bugs above gets marked fixed and web-platform-tests is updated.

CendioOssman added a commit to novnc/noVNC that referenced this pull request Oct 9, 2017
The browsers currently do not default to same-origin behaviour for
modules, so we need to be explicit in order for necessary
credentials to be passed along. This seems to be changing though,
but we need to wait for the browsers to actually roll out more
lenient defaults:

whatwg/fetch#585
@domfarolino
Copy link
Member

@domfarolino domfarolino commented Mar 6, 2018

It seems like WPTs are one of the things holding this PR and Mozilla's implementation back (given https://bugs.chromium.org/p/chromium/issues/detail?id=759543#c7). I'm happy to work on this if nobody else has started.

@annevk
Copy link
Member Author

@annevk annevk commented Apr 5, 2018

@domfarolino created web-platform-tests changes in web-platform-tests/wpt#9911 and is planning to go ahead in Chrome. (Unfortunately there isn't much test coverage for this today.)

I wonder if we should simultaneously change module workers since that's the only other feature that exposes this default at the moment. @domfarolino what do you think?

@annevk
Copy link
Member Author

@annevk annevk commented Apr 5, 2018

(And I guess that aspect of the feature isn't tested then? @domenic?)

@getify
Copy link

@getify getify commented Jul 9, 2018

Seems like Chrome stable and FF nightly or so?

Yes, I happened to be checking in FF nightly when I responded earlier. But AFAICT it's already in FF stable -- v61 from a few weeks ago.

So apparently I just happened to get caught by this in the gap (about a month, it seems?) between FF and Chrome going stable with it.

Anyone know when Safari will be updating this (stable)?

@yoavweiss
Copy link
Collaborator

@yoavweiss yoavweiss commented Jul 9, 2018

Maybe @cdumez or @youennf would.

@cdumez
Copy link

@cdumez cdumez commented Jul 9, 2018

Definitely something for @youennf

mislav added a commit to github/fetch that referenced this pull request Jul 25, 2018
MattiasBuelens added a commit to MattiasBuelens/yetch that referenced this pull request Jul 30, 2018
okuoku added a commit to yuniscm/yuniappjs-pkg that referenced this pull request Jan 16, 2019
It was changed in
whatwg/fetch#585
but it'd be better not to depend on it now.
@annevk
Copy link
Member Author

@annevk annevk commented May 20, 2019

@Andreas-Hjortland thanks for taking the time to point that out, please see #901 for a discussion. In particular, it's indeed confusing, but is distinct from the API.

AlanGreene added a commit to AlanGreene/dashboard that referenced this pull request Oct 1, 2019
Ensure we set `credentials: 'same-origin'` so that all
browsers send credentials on fetch requests, but only for
same-origin requests. This is to address an issue with
FF ESR (60) which was not sending credentials.

Other browser default to 'same-origin', but FF ESR requires
it explicitly. This behaviour was changed to match other
browsers from FF61: whatwg/fetch#585 (comment)
tekton-robot added a commit to tektoncd/dashboard that referenced this pull request Oct 1, 2019
Ensure we set `credentials: 'same-origin'` so that all
browsers send credentials on fetch requests, but only for
same-origin requests. This is to address an issue with
FF ESR (60) which was not sending credentials.

Other browser default to 'same-origin', but FF ESR requires
it explicitly. This behaviour was changed to match other
browsers from FF61: whatwg/fetch#585 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

None yet