Skip to content

Use the correct origin in fetch - #18882

Merged
bors-servo merged 2 commits into
servo:masterfrom
KiChjang:fix-origin
Nov 15, 2017
Merged

bors-servo merged 2 commits into
servo:masterfrom
KiChjang:fix-origin

Conversation

@KiChjang

@KiChjang KiChjang commented Oct 14, 2017 •

Copy link
Copy Markdown
Contributor

Fixes #18147.


This change is Reviewable

@highfive

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

@highfive

Copy link
Copy Markdown

warning Warning warning

  • These commits modify net code, but no tests are modified. Please consider adding a test!

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Oct 14, 2017
@KiChjang KiChjang changed the title Use the correct origin in fetch (WIP) Use the correct origin in fetch Oct 14, 2017
@KiChjang

Copy link
Copy Markdown
Contributor Author

@bors-servo try

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit 6b684e5 with merge 05c277e...

bors-servo pushed a commit that referenced this pull request Oct 14, 2017
(WIP) Use the correct origin in fetch

Fixes #18147.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18882)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - linux-rel-wpt

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Oct 14, 2017
@KiChjang

Copy link
Copy Markdown
Contributor Author

So the problem here is always with the case where we have to do cross-origin redirects... somehow the tests do not expect the request's origin to be the original document's URL's origin...

Comment thread components/net/http_loader.rs Outdated
let same_origin = location_url.origin() == request.current_url().origin();
let same_origin = match request.origin {
Origin::Origin(ref origin) => *origin == location_url.origin(),
Origin::Client => false,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this correct?

https://fetch.spec.whatwg.org/#concept-request-origin says you are not supposed to have a "client" value at this point in time, so at the very least that FIXME needs to stay.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because every time we create a request, we make sure to initialize it with the global's origin, so that the origin can never be client.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Make it panic, then.

@highfive highfive removed the S-tests-failed The changes caused existing tests to fail. label Oct 21, 2017
@KiChjang

Copy link
Copy Markdown
Contributor Author

@bors-servo try

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit 9b3ddf3 with merge f8ccaae46d88d4be398c94b74113356ff14575d4...

@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - linux-rel-wpt

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Oct 21, 2017
@highfive highfive removed the S-tests-failed The changes caused existing tests to fail. label Oct 21, 2017
@KiChjang

Copy link
Copy Markdown
Contributor Author

@bors-servo try

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit 86c9903 with merge 7c32d24...

bors-servo pushed a commit that referenced this pull request Oct 21, 2017
(WIP) Use the correct origin in fetch

Fixes #18147.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18882)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - mac-rel-wpt3

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Oct 21, 2017
@mbrubeck mbrubeck removed their assignment Oct 21, 2017
@KiChjang

Copy link
Copy Markdown
Contributor Author

I think I've found the problem - in HTTP redirect fetch step 10, we shouldn't be using the same_origin variable that we created at step 7, because that compares the location URL's origin against the request's origin, while what we actually need there is the origin of request's current URL and location URL's origin.

@highfive highfive removed the S-tests-failed The changes caused existing tests to fail. label Oct 25, 2017
@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Nov 3, 2017
@KiChjang KiChjang removed the S-needs-tests New tests have been requested by a reviewer. label Nov 3, 2017

@jdm jdm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks good if the test fails without this change!

@KiChjang

Copy link
Copy Markdown
Contributor Author

@jdm This is actually incredibly hard to test for. You mentioned on IRC:

so I suspect that a test case that would reveal the problem is if we had a request that started same-origin, 302 to a cross-origin URL (a.com) with no credentials, and that does a 302 to a same-origin (a.com) URL with credentials

Turns out the new code does indeed skip over the check at step 7, but then immediately fails at step 8:

If CORS flag is set and actualResponse’s location URL includes credentials, then return a network error.

The second redirection has the CORS flag set, and does include credentials, so it'll always fail.

@KiChjang

KiChjang commented Nov 10, 2017 •

Copy link
Copy Markdown
Contributor Author

So an idea I have here is to check the error message and ensure that it's generating the error message from step 8, instead of step 7. But in order to do so, I'll have to change this line here to return the error that was encountered during fetch, instead of always returning "Network error occurred":

fn process_response(&mut self, fetch_metadata: Result<FetchMetadata, NetworkError>) {
let promise = self.fetch_promise.take().expect("fetch promise is missing").root();
// JSAutoCompartment needs to be manually made.
// Otherwise, Servo will crash.
let promise_cx = promise.global().get_cx();
let _ac = JSAutoCompartment::new(promise_cx, promise.reflector().get_jsobject().get());
match fetch_metadata {
// Step 4.1
Err(_) => {
promise.reject_error(Error::Type("Network error occurred".to_string()));
self.fetch_promise = Some(TrustedPromise::new(promise));
self.response_object.root().set_type(DOMResponseType::Error);
return;
},

@KiChjang

Copy link
Copy Markdown
Contributor Author

Wow ok, that also comes with another problem - since this error string is specific to Servo, I need to extract this test out of WPT and put it under tests/wpt/mozilla/, but it looks like we don't have any testing infrastructure for doing CORS under that directory...

@KiChjang KiChjang changed the title Use the correct origin in fetch [WIP] Use the correct origin in fetch Nov 10, 2017
@jdm

jdm commented Nov 15, 2017

Copy link
Copy Markdown
Member

Ok, I've looked over the code and I do not believe it's worth all the effort to make a testcase that demonstrates this working correctly. It's particularly challenging because it's only this particular piece of code that gets the origin check wrong; the most important one in main_fetch does it right, which is why the cors flag is set. Therefore, let's remove 91c2b79 (because network errors are supposed to be opaque to content code) and let's remove 833501b as well. r=me with those omissions!

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Nov 15, 2017
@jdm jdm changed the title [WIP] Use the correct origin in fetch Use the correct origin in fetch Nov 15, 2017
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Nov 15, 2017
@KiChjang

Copy link
Copy Markdown
Contributor Author

@bors-servo r=jdm

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 1c8d049 has been approved by jdm

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Nov 15, 2017
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 1c8d049 with merge c988460...

bors-servo pushed a commit that referenced this pull request Nov 15, 2017
Use the correct origin in fetch

Fixes #18147.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18882)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev
Approved by: jdm
Pushing c988460 to master...

@bors-servo
bors-servo merged commit 1c8d049 into servo:master Nov 15, 2017
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Nov 15, 2017
@KiChjang
KiChjang deleted the fix-origin branch March 31, 2018 05:21
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.

6 participants