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

Avoid using the CORS flag to reset request's origin in redirects #594

Merged
merged 4 commits into from May 28, 2018

Conversation

annevk
Copy link
Member

@annevk annevk commented Aug 31, 2017

Otherwise things go wrong for "no-cors" POST redirects.

Fixes #593.


Preview | Diff

@annevk
Copy link
Member Author

annevk commented Aug 31, 2017

cc @davidben @yutakahirano @fmarier

@annevk annevk added the needs tests Moving the issue forward requires someone to write tests label Aug 31, 2017
Copy link
Collaborator

@davidben davidben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remembered this thing. Sorry, if this was waiting on a review from me. :-(

@annevk
Copy link
Member Author

annevk commented May 8, 2018

@davidben thanks, this also needs some tests still. Have you written any per chance?

@yutakahirano
Copy link
Member

This affects canvas tainting and friends, right?

request’s current url’s origin is same origin with request’s origin and CORS flag is unset
  => Set request’s response tainting to "basic".

@annevk
Copy link
Member Author

annevk commented May 8, 2018

Very good point, it would and that's not desirable.

@annevk annevk added the do not merge yet Pull request must not be merged per rationale in comment label May 8, 2018
@annevk
Copy link
Member Author

annevk commented May 24, 2018

So the alternative I can think of here is that we always preserve request's origin to its initial value and instead set a tainted origin flag during redirects. We then use that flag for the Origin header as well as the CORS literal origin comparison.

@annevk annevk force-pushed the annevk/redirect-origin-reset branch from 1a8272d to 49420f8 Compare May 24, 2018 08:57
@annevk
Copy link
Member Author

annevk commented May 24, 2018

I pushed a commit that does that, what do you think @yutakahirano?

@yutakahirano
Copy link
Member

Sounds reasonable but don't we need to update the origin usage of preflight cache?

@annevk
Copy link
Member Author

annevk commented May 24, 2018

I think that was already somewhat broken since it stored the actual origin, which for an opaque origin would always be unique. I guess we could add a guard to not add an entry to the cache if the tainted origin flag is set?

@annevk
Copy link
Member Author

annevk commented May 24, 2018

I suspect the problem with the preflight cache dates back from when I added support redirects following a successful preflight. I don't think I fully considered how the preflight cache should behave in cases where the request's origin was opaque.

Most performant would probably be to change the origin key into a byte sequence and use null if the tainted origin flag is set.

@annevk
Copy link
Member Author

annevk commented May 24, 2018

I tried to address the problem with the CORS-preflight cache by using a serialized origin as key. @yutakahirano @mikewest let me know what you all think.

@annevk
Copy link
Member Author

annevk commented May 24, 2018

I also filed #735 on defining the CORS-preflight cache in terms of proper data structures.

<a for=request>referrer policy</a> is <var>request</var>'s <a for=request>referrer policy</a>.
<a for=request>referrer</a> is <var>request</var>'s <a for=request>referrer</a>,
<a for=request>referrer policy</a> is <var>request</var>'s <a for=request>referrer policy</a>, and
<a for=request>tainted origin flag</a> is <var>request</var>'s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change needed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I was wrong, it's needed.

annevk added a commit to web-platform-tests/wpt that referenced this pull request May 25, 2018
@annevk
Copy link
Member Author

annevk commented May 25, 2018

Thanks. I created a basic test at web-platform-tests/wpt#11164 that can be expanded. It seems that Safari omits the Origin header upon redirects (rather than using the explicit null value) and Firefox retains the original value. Chrome does it correct.

@annevk annevk removed needs tests Moving the issue forward requires someone to write tests do not merge yet Pull request must not be merged per rationale in comment labels May 25, 2018
@annevk
Copy link
Member Author

annevk commented May 28, 2018

@annevk annevk merged commit af45ce3 into master May 28, 2018
@annevk annevk deleted the annevk/redirect-origin-reset branch May 28, 2018 09:17
annevk added a commit to web-platform-tests/wpt that referenced this pull request May 28, 2018
@yutakahirano
Copy link
Member

I have a question; Don't we need to set CORS flag when tainted in https://fetch.spec.whatwg.org/#http-redirect-fetch? That flag was set previously due to the origin manipulation.

@annevk
Copy link
Member Author

annevk commented Jun 6, 2018

Hmm, should we change the first conditional of step 5 of main fetch to:

request's current url's origin is same origin with request's origin, CORS flag is unset, and either request's tainted origin flag is unset or request's mode is not "cors"

I think setting the CORS flag would not work since that would make "no-cors" follow CORS code paths.

@annevk
Copy link
Member Author

annevk commented Jun 6, 2018

Filed #756 to track this, thanks!

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Jun 10, 2018
Automatic update from web-platform-testsOrigin header and 308 redirect

For whatwg/fetch#594.
--

wpt-commits: 89ae808d4ba430f83f8bc185b69108cf10070599
wpt-pr: 11164
xeonchen pushed a commit to xeonchen/gecko-cinnabar that referenced this pull request Jun 12, 2018
Automatic update from web-platform-testsOrigin header and 308 redirect

For whatwg/fetch#594.
--

wpt-commits: 89ae808d4ba430f83f8bc185b69108cf10070599
wpt-pr: 11164
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Oct 3, 2019
Automatic update from web-platform-testsOrigin header and 308 redirect

For whatwg/fetch#594.
--

wpt-commits: 89ae808d4ba430f83f8bc185b69108cf10070599
wpt-pr: 11164

UltraBlame original commit: cd57c997c98b496ed5c775316bc9bcafc3c6677c
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 3, 2019
Automatic update from web-platform-testsOrigin header and 308 redirect

For whatwg/fetch#594.
--

wpt-commits: 89ae808d4ba430f83f8bc185b69108cf10070599
wpt-pr: 11164

UltraBlame original commit: cd57c997c98b496ed5c775316bc9bcafc3c6677c
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 3, 2019
Automatic update from web-platform-testsOrigin header and 308 redirect

For whatwg/fetch#594.
--

wpt-commits: 89ae808d4ba430f83f8bc185b69108cf10070599
wpt-pr: 11164

UltraBlame original commit: cd57c997c98b496ed5c775316bc9bcafc3c6677c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

3 participants