Skip to content

Implement HSTS fetch step - #14716

Merged
bors-servo merged 1 commit into
servo:masterfrom
nmvk:hsts
Dec 29, 2016
Merged

bors-servo merged 1 commit into
servo:masterfrom
nmvk:hsts

Conversation

@nmvk

@nmvk nmvk commented Dec 24, 2016 •

Copy link
Copy Markdown
Contributor

Implemented step nine of the main fetch. If current URL scheme is 'HTTP' and
current URL's host is domain and if current URL's host matched with Known
HSTS Host Domain Name Matching results in either a superdomain match with
an asserted includeSubDomains directive or a congruent match then we
change request scheme to 'https'. This change has been made in method.rs

A test case to validate this has been added in fetch.rs. For asserting
https scheme, a https localhost was required. For this purpose I have
created a self-signed certificate and refactored fetch-context and
connector.rs to programmatically trust this certificate for running this
test case.

This should fix #14363


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix Implement HSTS #14363
  • There are tests for these changes

This change is Reviewable

@highfive

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

  • @KiChjang: components/net/fetch/methods.rs, components/net/resource_thread.rs, components/net/http_loader.rs, components/net/connector.rs

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Dec 24, 2016
@nmvk
nmvk force-pushed the hsts branch 2 times, most recently from 8fb4c4d to 24a883c Compare December 25, 2016 08:24
@nmvk

nmvk commented Dec 25, 2016 •

Copy link
Copy Markdown
Contributor Author

Travis failure The command "./mach test-stylo" exited with 101. not due to the current change.

@jdm

jdm commented Dec 25, 2016

Copy link
Copy Markdown
Member

That's #14723 .

@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #14741) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Dec 27, 2016
@nmvk

nmvk commented Dec 28, 2016

Copy link
Copy Markdown
Contributor Author

I have addressed conflicts. @emilio did you get a chance to review the changes?

@emilio

emilio commented Dec 28, 2016

Copy link
Copy Markdown
Member

I think @jdm or @Ms2ger are more suited to review this than me.

There should probably be a WPT test or similar for this.

@bors-servo try

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit e8099df with merge 1ccb92f...

bors-servo pushed a commit that referenced this pull request Dec 28, 2016
Implement HSTS fetch step

Implemented step nine of the main fetch. If current URL scheme is 'HTTP' and
current URL's host is domain and if current URL's host matched with Known
HSTS Host Domain Name Matching results in either a superdomain match with
an asserted includeSubDomains directive or a congruent match then we
change request scheme to 'https'. This change has been made in method.rs

A test case to validate this has been added in fetch.rs. For asserting
https scheme, a https localhost was required. For this purpose I have
created a self-signed certificate and refactored fetch-context and
connector.rs to programmatically trust this certificate for running this
test case.

This should fix #14363
<!-- Please describe your changes on the following line: -->

---
<!-- 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 #14363

<!-- Either: -->
- [X] There are tests for these changes

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

<!-- 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/14716)
<!-- Reviewable:end -->
@emilio

emilio commented Dec 28, 2016

Copy link
Copy Markdown
Member

@bors-servo r? @Ms2ger

@highfive highfive assigned Ms2ger and unassigned emilio Dec 28, 2016
@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 Dec 28, 2016
@nmvk

nmvk commented Dec 28, 2016

Copy link
Copy Markdown
Contributor Author

Is the test failure due to network issue?

@emilio emilio 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.

Seems like the failures may be legit? We can retry to verify it.

Other option would be that that check makes stuff immensely slower, in which case we'd need a faster data-structure for HstsList.

Comment thread components/net/fetch/methods.rs Outdated

// Step 9
// TODO this step (HSTS)
if request.current_url().scheme() == "http" && request.current_url().domain() != None {

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.

nit: use request.current_url().domain().is_some()?

@emilio

emilio commented Dec 28, 2016

Copy link
Copy Markdown
Member

@bors-servo retry

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit e8099df with merge 35d62a5...

bors-servo pushed a commit that referenced this pull request Dec 28, 2016
Implement HSTS fetch step

Implemented step nine of the main fetch. If current URL scheme is 'HTTP' and
current URL's host is domain and if current URL's host matched with Known
HSTS Host Domain Name Matching results in either a superdomain match with
an asserted includeSubDomains directive or a congruent match then we
change request scheme to 'https'. This change has been made in method.rs

A test case to validate this has been added in fetch.rs. For asserting
https scheme, a https localhost was required. For this purpose I have
created a self-signed certificate and refactored fetch-context and
connector.rs to programmatically trust this certificate for running this
test case.

This should fix #14363
<!-- Please describe your changes on the following line: -->

---
<!-- 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 #14363

<!-- Either: -->
- [X] There are tests for these changes

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

<!-- 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/14716)
<!-- Reviewable:end -->
@emilio

emilio commented Dec 28, 2016

Copy link
Copy Markdown
Member

IMO the hsts list seems pretty big to use a vec as a backing store, but maybe other people have different opinions.

@nmvk

nmvk commented Dec 28, 2016 •

Copy link
Copy Markdown
Contributor Author

Thanks, @emilio, Maybe I could refactor HstsList to use HashSet or HashMap which could provide faster lookup?

@bors-servo

Copy link
Copy Markdown
Contributor

@emilio

emilio commented Dec 28, 2016

Copy link
Copy Markdown
Member

Tests seem green, so it's likely to have been another kind of error. I've opened #14756 to change the underlying storage of the HSTS list. I think it's worth to land that refactoring separately as a followup.

@highfive highfive removed the S-tests-failed The changes caused existing tests to fail. label Dec 28, 2016

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

Great work!

Comment thread resources/certificate.crt
@@ -0,0 +1,22 @@
-----BEGIN CERTIFICATE-----

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 file should be called self_signed_certificate_for_testing.crt to make its purpose clear ;)

Comment thread resources/privatekey.key
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----

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 should be called privatekey_for_testing.key.

Comment thread tests/unit/net/fetch.rs Outdated
list.push(HstsEntry::new("localhost".to_owned(), IncludeSubdomains::NotIncluded, None)
.unwrap());
}
let do_fetch = |url: ServoUrl| {

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.

I don't think having this closure makes the test any more readable, so let's remove it.

Comment thread tests/unit/net/fetch.rs
fn test_fetch_with_hsts() {
static MESSAGE: &'static [u8] = b"";
let handler = move |_: HyperRequest, response: HyperResponse| {
response.send(MESSAGE).unwrap();

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.

Let's have the response contain the scheme of the request's URL instead. This will let us verify that the server never receives a non-HTTPS connection.

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.

If I correctly understand, you want request.url.scheme() to be sent as part of response body?. Here we use hyper::server::request::Request which does not capture information about request scheme. If we make a non-HTTPS connection to the server, then we get response error saying "Connection reset"

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.

Ah, good point. This test is fine as-is, in that case.

@jdm jdm assigned jdm and unassigned Ms2ger Dec 28, 2016
@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. S-needs-rebase There are merge conflict errors. labels Dec 28, 2016
Implemented step nine of the main fetch. If current URL scheme is 'HTTP'
and current URL's host is domain and if current URL's host matched with
Known
HSTS Host Domain Name Matching results in either a superdomain match with
an asserted includeSubDomains directive or a congruent match then we
change request scheme to 'https'. This change has been made in method.rs

A test case to validate this has been added in fetch.rs. For asserting
https scheme, a https localhost was required. For this purpose I have
created a self-signed certificate and refactored fetch-context and
connector.rs to programmatically trust this certificate for running this
test case.
@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 Dec 29, 2016
@jdm

jdm commented Dec 29, 2016

Copy link
Copy Markdown
Member

@bors-servo: r+
Thanks for fixing this and figuring out how to use HTTPS servers in unit tests!

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 6020b4c 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 Dec 29, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 6020b4c with merge c7991d5...

bors-servo pushed a commit that referenced this pull request Dec 29, 2016
Implement HSTS fetch step

Implemented step nine of the main fetch. If current URL scheme is 'HTTP' and
current URL's host is domain and if current URL's host matched with Known
HSTS Host Domain Name Matching results in either a superdomain match with
an asserted includeSubDomains directive or a congruent match then we
change request scheme to 'https'. This change has been made in method.rs

A test case to validate this has been added in fetch.rs. For asserting
https scheme, a https localhost was required. For this purpose I have
created a self-signed certificate and refactored fetch-context and
connector.rs to programmatically trust this certificate for running this
test case.

This should fix #14363
<!-- Please describe your changes on the following line: -->

---
<!-- 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 #14363

<!-- Either: -->
- [X] There are tests for these changes

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

<!-- 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/14716)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

@bors-servo
bors-servo merged commit 6020b4c into servo:master Dec 29, 2016
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Dec 29, 2016
@bors-servo bors-servo mentioned this pull request Dec 29, 2016
4 tasks done
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.

Implement HSTS

6 participants