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

check http_state in determine_request_referrer #26546

Merged
merged 2 commits into from May 19, 2020

Conversation

@splav
Copy link
Contributor

splav commented May 16, 2020

Check https status inside determine_request_referrer.

  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #14506 (GitHub issue number if applicable)
  • There are tests for these changes OR
  • These changes do not require tests because ___
@highfive
Copy link

highfive commented May 16, 2020

Heads up! This PR modifies the following files:

  • @asajeffrey: components/script/fetch.rs
  • @KiChjang: components/script/fetch.rs, components/net/fetch/methods.rs, components/net/tests/http_loader.rs, components/net_traits/request.rs, components/net/http_loader.rs
@splav
Copy link
Contributor Author

splav commented May 16, 2020

Sadly, it seems there are no tests for HttpsState::Deprecated value. At least in enabled tests.

/// <https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy>
fn is_origin_trustworthy(url: ServoUrl) -> bool {
match url.origin() {
// Step 1
ImmutableOrigin::Opaque(_) => false,
ImmutableOrigin::Tuple(_, _, _) => {
// Step 3
if url.scheme() == "https" || url.scheme() == "wss" {
return true;
}
// Step 4-5 TODO
// Step 6
if url.scheme() == "file" {
return true;
}
// Step 7-8 TODO
// Step 9
false
},
}
}
Comment on lines 208 to 228

This comment has been minimized.

Copy link
@CYBAI

CYBAI May 17, 2020

Collaborator

IIRC, we've had this function in urlhelper so you can just use UrlHelper::is_origin_trustworthy.

// https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy
pub fn is_origin_trustworthy(url: &ServoUrl) -> bool {
// Step 1
if !url.origin().is_tuple() {
return false;
}
// Step 3
if url.scheme() == "https" || url.scheme() == "wss" {
true
// Step 4
} else if url.host().is_some() {
let host = url.host_str().unwrap();
host == "127.0.0.0/8" || host == "::1/128"
// Step 6
} else {
url.scheme() == "file"
}
}
}

@splav
Copy link
Contributor Author

splav commented May 17, 2020

@CYBAI
Copy link
Collaborator

CYBAI commented May 17, 2020

  1. It should be moved to somewhere in the net, may be there is something like net/url helpers? What is the best place?

Yes, agree! @gterzian tried to move it as a method of ServoUrl in #26317 ; maybe that will be a good place?

See https://github.com/servo/servo/pull/26317/files#diff-cac78be29c466ffe8160ad29af53e214R173-R191

  1. The check for local ip is incorrect, I'll fix it using Rust std Ipv*Addr structs methods.

👍

@splav
Copy link
Contributor Author

splav commented May 17, 2020

Fixed is_origin_trustworthy + moved it to ServoUrl

Copy link
Member

jdm left a comment

We're missing initializing the request's https state in Document::fetch_async.

We should also make net_request_from_global in component/script/fetch.rs initialize the https_state member; this might require us to:

  • add a https_state method on GlobalScope
  • make load_whole_resource return the HTTPS state
  • update the global scope's https state based on the result of the load

Finally we should add the request's HTTPS state as an argument to load_whole_resource and set the Request's https_state member before starting the request.

@@ -413,6 +418,7 @@ impl Request {
redirect_count: 0,
response_tainting: ResponseTainting::Basic,
csp_list: None,
https_state: HttpsState::None,

This comment has been minimized.

Copy link
@jdm

jdm May 17, 2020

Member

We should make sure that the new https_state member is initialized in net_request_from_global in components/script/dom/request.rs.

@@ -128,6 +129,7 @@ fn request_init_from_request(request: NetTraitsRequest) -> RequestBuilder {
parser_metadata: request.parser_metadata,
initiator: request.initiator,
csp_list: None,
https_state: HttpsState::None,

This comment has been minimized.

Copy link
@jdm

jdm May 17, 2020

Member

This should be request.https_state, right?

This comment has been minimized.

Copy link
@splav

splav May 17, 2020

Author Contributor

Yes, missed that NetTraitsRequest means 'Request from net_traits'

@jdm jdm assigned jdm and unassigned Manishearth May 17, 2020
@splav splav force-pushed the splav:tls-protected-checks branch from 625c47b to 788ae3f May 18, 2020
@splav splav force-pushed the splav:tls-protected-checks branch 2 times, most recently from b7d83d2 to 728fd0e May 18, 2020
@splav
Copy link
Contributor Author

splav commented May 18, 2020

I want to believe that all requested changes are fixed now.

@splav
Copy link
Contributor Author

splav commented May 18, 2020

Forgot unit tests, fixing.

@splav splav force-pushed the splav:tls-protected-checks branch 2 times, most recently from cc83ffd to 0c42ae7 May 18, 2020
@@ -395,6 +395,7 @@ impl DedicatedWorkerGlobalScope {
Ok((metadata, bytes)) => (metadata, bytes),
};
scope.set_url(metadata.final_url);
global_scope.set_https_state(metadata.https_state);

This comment has been minimized.

Copy link
@jdm

jdm May 19, 2020

Member

Since load_whole_resource now uses the default value of global's https state when we call it earlier in this file, please set global_scope's https_state to the https_state of current_global before calling load_whole_resource. This call to set_https_state should remain, however.

This comment has been minimized.

Copy link
@splav

splav May 19, 2020

Author Contributor

Done, essentially it makes the worker global scope inherit parent global scope https state.

@splav splav force-pushed the splav:tls-protected-checks branch from 0c42ae7 to 0bf9a69 May 19, 2020
@@ -375,6 +375,8 @@ impl DedicatedWorkerGlobalScope {
let scope = global.upcast::<WorkerGlobalScope>();
let global_scope = global.upcast::<GlobalScope>();

global_scope.set_https_state(current_global.get_https_state());

This comment has been minimized.

Copy link
@jdm

jdm May 19, 2020

Member

I'm 99% confident that this doesn't build, since current_global can't be moved between threads. We need to get the https state value before spawning the new thread instead.

This comment has been minimized.

Copy link
@splav

splav May 19, 2020

Author Contributor

Yes, fixed that. Strangely it did build. May be some caching... Also sometimes rustc crashes and builds fine after rerun.

@splav splav force-pushed the splav:tls-protected-checks branch from 0bf9a69 to 8ca5ebb May 19, 2020
@splav splav force-pushed the splav:tls-protected-checks branch from 8ca5ebb to 357b486 May 19, 2020
@jdm
Copy link
Member

jdm commented May 19, 2020

@bors-servo try=wpt

@bors-servo
Copy link
Contributor

bors-servo commented May 19, 2020

Trying commit 357b486 with merge e82b9da...

bors-servo added a commit that referenced this pull request May 19, 2020
check http_state in determine_request_referrer

<!-- Please describe your changes on the following line: -->
Check https status inside determine_request_referrer.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #14506 (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
@bors-servo
Copy link
Contributor

bors-servo commented May 19, 2020

☀️ Test successful - status-taskcluster
State: approved= try=True

@jdm
Copy link
Member

jdm commented May 19, 2020

Huh, I'm surprised there are still no test result changes. I want to figure out what's missing before we merge this.

@splav
Copy link
Contributor Author

splav commented May 19, 2020

Ok. If there are candidates - I can investigate concrete tests. I'll try to look for appropriate tests manually though.

@jdm
Copy link
Member

jdm commented May 19, 2020

I dug into it, and it turns out that there are no referrer-policy tests that start in an HTTPS context and make an HTTP request. This appears to be an oversight in the test suite generation, based on:

It looks like either the mixed-content exclusions are over-enthusiastic, or the author thought that the mixed content standard subsumes this for some reason.

I'm inclined to merge these changes and investigate extending the test suite separately.

@jdm
Copy link
Member

jdm commented May 19, 2020

@bors-servo
Copy link
Contributor

bors-servo commented May 19, 2020

📌 Commit 357b486 has been approved by jdm

@splav
Copy link
Contributor Author

splav commented May 19, 2020

Random thought:
If the previous request was a modern https the it was handled correctly with checking url scheme.
Modern <=> "https" scheme; None <=> "http" scheme.
The only case not handled correctly previously I can imagine - Deprecated state from previous request.
I failed to find any uses of HttpsState::Deprecated in the code and is up to implementation what to consider deprecated. So, no fixed tests here does not seem strange.

The other thing I fixed - is_origin_trustworthy implementation. And here I do expect some test results changes.

@jdm
Copy link
Member

jdm commented May 19, 2020

@bors-servo r-
Let's answer the question about is_origin_trustworthy before merging.

@jdm
Copy link
Member

jdm commented May 19, 2020

Looks like the is_origin_trustworthy changes are difficult to test as part of the WPT harness, so let's merge these.
@bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented May 19, 2020

📌 Commit 357b486 has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented May 19, 2020

Testing commit 357b486 with merge 4edf37a...

bors-servo added a commit that referenced this pull request May 19, 2020
check http_state in determine_request_referrer

<!-- Please describe your changes on the following line: -->
Check https status inside determine_request_referrer.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #14506 (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
@bors-servo
Copy link
Contributor

bors-servo commented May 19, 2020

💔 Test failed - status-taskcluster

@jdm
Copy link
Member

jdm commented May 19, 2020

@bors-servo
Copy link
Contributor

bors-servo commented May 19, 2020

Testing commit 357b486 with merge e17b53e...

@bors-servo
Copy link
Contributor

bors-servo commented May 19, 2020

☀️ Test successful - status-taskcluster
Approved by: jdm
Pushing e17b53e to master...

@bors-servo bors-servo merged commit e17b53e into servo:master May 19, 2020
2 checks passed
2 checks passed
Community-TC (pull_request) TaskGroup: success
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

6 participants
You can’t perform that action at this time.