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

Implement HSTS (preload-only) #6490

Merged
merged 24 commits into from Jul 22, 2015
Merged

Implement HSTS (preload-only) #6490

merged 24 commits into from Jul 22, 2015

Conversation

@samfoo
Copy link
Contributor

samfoo commented Jun 26, 2015

Implement HSTS (preload-only) #6105

  • Downloads the HSTS preload list from the chromium repo (same as gecko), then convert it to a list appropriate for servo.
  • Reads the preload list when creating a resource task, and implements STS for those domains.

Still todo:

  • Read Strict-Transport-Security headers from servers and add details to the in-memory HSTS list. (note: this requires hyper or servo to implement an STS header struct. Hyper seems like the appropriate location, so I will create an issue/PR there soon). The work for this is nearly done with the exception of adding a new ControlMsg and the new header.
  • Persist HSTS list to disk with known hosts (perhaps a different issue should be raised for this?)

Review on Reviewable

@highfive
Copy link

highfive commented Jun 26, 2015

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @jdm (or someone else) soon.

@hoppipolla-critic-bot
Copy link

hoppipolla-critic-bot commented Jun 26, 2015

Critic review: https://critic.hoppipolla.co.uk/r/5393

This is an external review system which you may optionally use for the code review of your pull request.

In order to help critic track your changes, please do not make in-place history rewrites (e.g. via git rebase -i or git commit --amend) when updating this pull request.

@jdm
Copy link
Member

jdm commented Jul 6, 2015

Great work @samfoo! I appreciate the way you've split up the commits. Sorry for the delay in looking at this PR; I've skimmed all of the commits so far, and I'll do a thorough review soon.

@jdm jdm self-assigned this Jul 6, 2015
@jdm
Copy link
Member

jdm commented Jul 6, 2015

One significant change I'll request is to switch from including the fetching of the preload list as part of bootstrapping and make it an explicit choice to update the copy that's part of the tree. We should add a mach command to fetch it, and remove the new entry from the gitignore list.

@samfoo
Copy link
Contributor Author

samfoo commented Jul 7, 2015

@jdm Sure. Moving the preload from a bootstrap step to an explicit command shouldn't be too big of a change. I'll take a look at making it sometime this week.

@samfoo
Copy link
Contributor Author

samfoo commented Jul 7, 2015

Also note that since hyperium/hyper#590 (implementing the Strict-Transport-Security header) is now merged, whenever the next version bump of hyper happens, the non-preload STS implementation can be finished.

@bors-servo
Copy link
Contributor

bors-servo commented Jul 15, 2015

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

@jdm
Copy link
Member

jdm commented Jul 15, 2015

I've started reviewing this. Apologies for the continued delays!

@jdm jdm added the S-needs-rebase label Jul 15, 2015
@samfoo samfoo force-pushed the samfoo:hsts-preload branch from e45b03f to 7497006 Jul 16, 2015
@samfoo
Copy link
Contributor Author

samfoo commented Jul 16, 2015

I've rebased to resolve the conflicts. Let me know if there's something else I can do to help with this.

@jdm
Copy link
Member

jdm commented Jul 16, 2015

-S-needs-rebase -S-needs-rebase +S-needs-code-changes
This is such a great PR! Thanks for doing this work :D


Reviewed 5 of 5 files at r1, 2 of 2 files at r2, 2 of 2 files at r3, 1 of 1 files at r4, 2 of 2 files at r5, 2 of 2 files at r6, 5 of 5 files at r7, 2 of 2 files at r8, 2 of 2 files at r9, 2 of 2 files at r10, 2 of 2 files at r11, 1 of 1 files at r12, 1 of 1 files at r13, 1 of 1 files at r14, 4 of 4 files at r15, 5 of 5 files at r16.
Review status: all files reviewed at latest revision, 24 unresolved discussions, all commit checks successful.


components/net/resource_task.rs, line 159 [r1] (raw file):

read_resource_file(...).ok().and_then(|bytes| {
    from_utf8(bytes).ok().and_then(|content| {
        HSTSList::new_from_preload(content)
    })
})

components/net/resource_task.rs, line 186 [r1] (raw file):
I think we should move all of this HSTS-related code into a new hsts.rs file.


components/net/resource_task.rs, line 198 [r1] (raw file):
decode(preload_content).ok()


components/net/resource_task.rs, line 201 [r5] (raw file):
Let's make this an enum rather than a bool. We can still store a bool internally, though.


components/net/resource_task.rs, line 221 [r1] (raw file):
I would just use an if instead.


components/net/resource_task.rs, line 223 [r1] (raw file):
Can we not mutate the url in place?


components/net/resource_task.rs, line 261 [r2] (raw file):
Why not just use a mutable iterator and update include_subdomains in place, instead of using a fold?


components/net/resource_task.rs, line 311 [r12] (raw file):
@SimonSapin, is this necessary?


components/net/resource_task.rs, line 341 [r1] (raw file):
if let
This needs to happen in http_loader.rs instead, though, or we won't upgrade any redirects that occur.


components/net/resource_task.rs, line 370 [r11] (raw file):
if let


components/net/resource_task.rs, line 424 [r10] (raw file):
if let


components/net/resource_task.rs, line 425 [r8] (raw file):
I preferred the previous code which wasn't so clone-happy.


python/servo/bootstrap_commands.py, line 226 [r1] (raw file):
grammar nit: ; instead of ,


python/servo/bootstrap_commands.py, line 230 [r1] (raw file):
A comment explaining this would be useful.


tests/unit/net/resource_task.rs, line 6 [r1] (raw file):
nit: so far we've preferred single line imports on multiple lines than {} split across multiple lines.


tests/unit/net/resource_task.rs, line 24 [r1] (raw file):
As with the new hsts.rs in net, I think we should have a new test file for it too.


tests/unit/net/resource_task.rs, line 26 [r1] (raw file):
assert!(HSTSList::new_from_preload(mock_preload_content).is_some(), "preload list should not have parsed")


tests/unit/net/resource_task.rs, line 29 [r6] (raw file):
assert!(entry.is_none(), "able to create HSTSEntry with IPv6 host");


tests/unit/net/resource_task.rs, line 35 [r1] (raw file):
assert .is_some()


tests/unit/net/resource_task.rs, line 41 [r6] (raw file):
Same as above.


tests/unit/net/resource_task.rs, line 52 [r1] (raw file):
[0] instead of .get(0).unwrap()?


tests/unit/net/resource_task.rs, line 68 [r2] (raw file):
A test for adding multiple entries (or adding an entry to one with more than one existing entry) would have caught the earlier bug.


tests/unit/net/resource_task.rs, line 118 [r1] (raw file):
assert_eq


tests/unit/net/resource_task.rs, line 129 [r1] (raw file):
assert_eq


Comments from the review on Reviewable.io

@jdm
Copy link
Member

jdm commented Jul 16, 2015

Please leave extracting the HSTS code into new files until the very end in a separate commit; it will be easier for me to notice the changes related to my other comment that way :)

@jdm jdm removed the S-awaiting-review label Jul 16, 2015
@samfoo
Copy link
Contributor Author

samfoo commented Jul 18, 2015

Review status: all files reviewed at latest revision, 9 unresolved discussions, all commit checks successful.


components/net/resource_task.rs, line 215 [r2] (raw file):
Rust newbie. Fixed.


components/net/resource_task.rs, line 223 [r1] (raw file):
There's a "bug"/implementation detail in Url such that even though we update the scheme, it doesn't properly update the port internally. This meant that even when upgrading the URL to https, the connection was still attempted on port 80. Re-parsing the URL is a hack to get around this. I'll add a comment explaining it, and think about submitting a fix to rust-url


components/net/resource_task.rs, line 341 [r1] (raw file):
Excellent point. This same problem exists for host file resolution as well, I believe.


Comments from the review on Reviewable.io

@jdm
Copy link
Member

jdm commented Jul 18, 2015

Review status: all files reviewed at latest revision, 5 unresolved discussions, all commit checks successful.


components/net/resource_task.rs, line 449 [r1] (raw file):
Yep, see #6416 :)


Comments from the review on Reviewable.io

@samfoo
Copy link
Contributor Author

samfoo commented Jul 18, 2015

Still need to move the hsts list to the http_loader, but it's a slightly larger task than the rest.

@jdm
Copy link
Member

jdm commented Jul 18, 2015

Reviewed 3 of 3 files at r17, 2 of 2 files at r18, 6 of 6 files at r19, 4 of 4 files at r20.
Review status: all files reviewed at latest revision, 6 unresolved discussions, all commit checks successful.


components/net/hsts.rs, line 18 [r19] (raw file):
Let's use the regexes from resource_task.rs instead of duplicating them.


components/net/http_loader.rs, line 89 [r20] (raw file):
We're going to want this to be an Arc<Mutex<HSTSList>>, or we'll be cloning a large vector for every single request.


components/net/resource_task.rs, line 26 [r19] (raw file):
nit: these can be merged into one or multiple lines of {} that aren't longer than 100 chars.


components/net/resource_task.rs, line 263 [r20] (raw file):
Why not always have an HSTSList, just make it empty?


components/net/resource_task.rs, line 363 [r18] (raw file):
Let's use the enum in this message, too.


tests/unit/net/hsts.rs, line 137 [r19] (raw file):
?


Comments from the review on Reviewable.io

@jdm
Copy link
Member

jdm commented Jul 18, 2015

This is very close! I'm excited!

@bors-servo
Copy link
Contributor

bors-servo commented Jul 18, 2015

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

samfoo added 18 commits Jun 23, 2015
De-coupling makes testing a bit easier.
* No longer download the HSTS list as a bootstrap step
* Check the current revision of the HSTS list into source
* Lots of rust-isms
* Mutable iterator for modifying entries (much better)
* Don't pass a boolean to the HSTSEntry constructor, use an enum instead
* Don't clone when securing load data
* Comment about the Url bug
* Change remaining assert!(... == ...) to assert_eq!(..., ...)
This respects STS for redirects as well.
* Use regex from resource task
* Don't have an option of an HSTS list, default to empty
Cuts down on logger spam, and unnecessary Url::clone's
@samfoo samfoo force-pushed the samfoo:hsts-preload branch from 680842f to 118122d Jul 21, 2015
@jdm
Copy link
Member

jdm commented Jul 22, 2015

@bors-servo
Copy link
Contributor

bors-servo commented Jul 22, 2015

📌 Commit 118122d has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Jul 22, 2015

Testing commit 118122d with merge ab3d6c4...

bors-servo pushed a commit that referenced this pull request Jul 22, 2015
Implement HSTS (preload-only)

Implement HSTS (preload-only) #6105

* Downloads the HSTS preload list from the chromium repo (same as gecko), then convert it to a list appropriate for servo.
* Reads the preload list when creating a resource task, and implements STS for those domains.

Still todo:

* Read Strict-Transport-Security headers from servers and add details to the in-memory HSTS list. (note: this requires hyper or servo to implement an STS header struct. Hyper seems like the appropriate location, so I will create an issue/PR there soon). The work for this is nearly done with the exception of adding a new ControlMsg and the new header.
* Persist HSTS list to disk with known hosts (perhaps a different issue should be raised for this?)

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6490)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 22, 2015

☀️ Test successful - android, gonk, linux1, linux2, linux3, mac1, mac2, mac3

@bors-servo bors-servo merged commit 118122d into servo:master Jul 22, 2015
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
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.

None yet

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