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.
@annevk
Copy link
Member Author

annevk commented Aug 25, 2017

@Munter
Copy link

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

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

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

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 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

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 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 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 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 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

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

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

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 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 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 commented Sep 2, 2017 via email

@tyoshino
Copy link
Member

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

@annevk
Copy link
Member Author

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

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 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 commented Apr 5, 2018

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

chinnkarahoi pushed a commit to chinnkarahoi/noVNC that referenced this pull request Apr 11, 2022
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
chinnkarahoi pushed a commit to chinnkarahoi/noVNC that referenced this pull request Jan 27, 2023
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet