Skip to content

compiler/natives/src/net/http: Set Fetch credentials to same-origin. #486

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

Merged
merged 1 commit into from
Jul 5, 2016

Conversation

dmitshur
Copy link
Member

@dmitshur dmitshur commented Jul 4, 2016

This makes the behavior of http.DefaultTransport using Fetch API more similar as when using XHR API.

It's unfortunate to have to do this, since it's kinda magic, but this seems to be the most reasonable default. It's consistent with the previous behavior of XHR implementation.

There is no equivalent property in http.Request as far as I can tell. The only other way to set credentials would be to use req.AddCookie, but then one would need to get the cookie in JavaScript, which is not possible if that cookie has HttpOnly flag set.

It appears this is an unfortunate reality that we have to deal with to provide a useful http.DefaultTransport implementation on frontend, because of restrictions put into place due to security concerns on the web.

For reference, see:

https://fetch.spec.whatwg.org/#concept-request-credentials-mode
https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials

A request has an associated credentials mode, which is "omit", "same-origin", or "include". Unless stated otherwise, it is "omit".

https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials

Setting withCredentials has no effect on same-site requests.

So default XHR behavior without withCredentials set is like Fetch with "same-origin" credentials mode.

Updates #454.

/cc @dominikh

@dmitshur dmitshur force-pushed the fetch-set-credentials branch from 783023e to 36770b6 Compare July 4, 2016 23:35
This makes the behavior of http.DefaultTransport using Fetch API more
similar as when using XHR API.

It's unfortunate to have to do this, since it's kinda magic, but this
seems to be the most reasonable default. It's consistent with the
previous behavior of XHR implementation.

There is no equivalent property in http.Request as far as I can tell.
The only other way to set credentials would be to use req.AddCookie,
but then one would need to get the cookie in JavaScript, which is not
possible if that cookie has HttpOnly flag set.

It appears this is an unfortunate reality that we have to deal with to
provide a useful http.DefaultTransport implementation on frontend,
because of restrictions put into place due to security concerns on the web.

For reference, see:

https://fetch.spec.whatwg.org/#concept-request-credentials-mode
https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials

> A request has an associated credentials mode, which is "omit",
> "same-origin", or "include". Unless stated otherwise, it is "omit".

https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials

> Setting withCredentials has no effect on same-site requests.

So default XHR behavior without withCredentials set is like Fetch
with "same-origin" credentials mode.

Updates #454.
@dmitshur dmitshur force-pushed the fetch-set-credentials branch from 36770b6 to e5bfe69 Compare July 4, 2016 23:54
@neelance
Copy link
Member

neelance commented Jul 5, 2016

LGTM

@dmitshur dmitshur merged commit e5bfe69 into master Jul 5, 2016
@dmitshur dmitshur deleted the fetch-set-credentials branch July 5, 2016 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants