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

#14514 Implement port-based blocking #14623

Merged
merged 1 commit into from Dec 24, 2016
Merged

#14514 Implement port-based blocking #14623

merged 1 commit into from Dec 24, 2016

Conversation

@DominoTree
Copy link
Contributor

DominoTree commented Dec 17, 2016

Add check for bad ports to http_fetch(), return NetworkError::Internal if bad port/schema combination is seen.

Test added


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #14514 (github issue number if applicable).
  • There are tests for these changes OR

This change is Reviewable

@highfive
Copy link

highfive commented Dec 17, 2016

Heads up! This PR modifies the following files:

Copy link
Member

emilio left a comment

The rest looks good to me, thanks for doing that!

Probably @jdm wants to take a look. I'll do a try run to see if there are any wpt tests around testing this.

match request.url().port() {
Some(port) => {
let is_ftp: bool = request.url().scheme() == "ftp" && (port == 20 || port == 21);
let bad_ports: Vec<u16> = vec![1, 7, 9, 11, 13, 15, 17, 19, 20, 21, 22, 23, 25, 37, 42,

This comment has been minimized.

Copy link
@emilio

emilio Dec 19, 2016

Member

This can be a static array, and you can binary-search on it for speed.

// Bad port blocking - https://fetch.spec.whatwg.org/#block-bad-port
match request.url().port() {
Some(port) => {
let is_ftp: bool = request.url().scheme() == "ftp" && (port == 20 || port == 21);

This comment has been minimized.

Copy link
@emilio

emilio Dec 19, 2016

Member

I think the type annotation (: bool) is not needed, is it?

This comment has been minimized.

Copy link
@DominoTree

DominoTree Dec 19, 2016

Author Contributor

Just added this because it made things a bit clearer for me, but it's definitely not needed.

@@ -537,6 +537,23 @@ pub fn http_fetch(request: Rc<Request>,
done_chan: &mut DoneChannel,
context: &FetchContext)
-> Response {
// Bad port blocking - https://fetch.spec.whatwg.org/#block-bad-port
match request.url().port() {

This comment has been minimized.

Copy link
@emilio

emilio Dec 19, 2016

Member

Given the None arm is empty, you can do:

if let Some(port) = request.url.port() {
    // ...
}
@@ -60,6 +61,18 @@ fn test_fetch_response_is_not_network_error() {
}

#[test]
fn test_fetch_on_bad_port_is_network_error() {

This comment has been minimized.

Copy link
@emilio

emilio Dec 19, 2016

Member

Any chance we can write this down also as a web platform test (if it doesn't exist)?

@emilio
Copy link
Member

emilio commented Dec 19, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Dec 19, 2016

Trying commit dfdf0e9 with merge 166b4de...

bors-servo added a commit that referenced this pull request Dec 19, 2016
<!-- Please describe your changes on the following line: -->
Add check for bad ports to http_fetch(), return NetworkError::Internal if bad port/schema combination is seen.

Test added

---
<!-- 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 #14514 (github issue number if applicable).

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

<!-- 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/14623)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Dec 19, 2016

@@ -525,6 +525,8 @@ pub enum ConstellationMsg {
/// Network errors that have to be exported out of the loaders
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize, HeapSizeOf)]
pub enum NetworkError {
/// Request attempted on bad port - https://fetch.spec.whatwg.org/#block-bad-port
BadPort,

This comment has been minimized.

Copy link
@Ms2ger

Ms2ger Dec 19, 2016

Contributor

I don't think it's particularly useful to introduce a new variant here; Internal will be fine.

This comment has been minimized.

Copy link
@DominoTree

DominoTree Dec 19, 2016

Author Contributor

I was just using because it felt kinda hacky to compare strings in the unit test to confirm that the correct Internal error was returned from connecting to a bad port (and not simply a failed connection), but we can definitely remove it.

@emilio
Copy link
Member

emilio commented Dec 19, 2016

Please add a WPT test with this behaviour (since all existing tests passed).

You can find docs in how to do this in the file tests/wpt/README.md.

Thanks again! :)

@Ms2ger
Copy link
Contributor

Ms2ger commented Dec 20, 2016

Thanks! I think using promise_rejects and promise_test will be necessary to make the test work.

@DominoTree
Copy link
Contributor Author

DominoTree commented Dec 20, 2016

@Ms2ger Cool, I will look into that

for (var i = 0; i < BLOCKED_PORTS_LIST.length; i++) {
var blockedPort = BLOCKED_PORTS_LIST[i];
promise_test(t => {
return Promise.all([

This comment has been minimized.

Copy link
@jdm

jdm Dec 21, 2016

Member

No need for Promise.all here; we can simply use return promise_rejects(...).

This comment has been minimized.

Copy link
@DominoTree

DominoTree Dec 21, 2016

Author Contributor

Thanks, I'm a bit out of my element with this JavaScript stuff. Still trying a couple of things to make this work properly.

@DominoTree
Copy link
Contributor Author

DominoTree commented Dec 21, 2016

Think that should do it!

@Ms2ger
Copy link
Contributor

Ms2ger commented Dec 21, 2016

Test looks great, but I'm a little surprised you put the code in http_loader.rs, rather than in fn main_fetch(), as in the spec: https://fetch.spec.whatwg.org/#concept-main-fetch (step 5).

@DominoTree
Copy link
Contributor Author

DominoTree commented Dec 21, 2016

@Ms2ger My bad, I overlooked that in the spec. I've moved it into the proper place.

@emilio
Copy link
Member

emilio commented Dec 23, 2016

@bors-servo r+

Thanks! :)

@bors-servo
Copy link
Contributor

bors-servo commented Dec 23, 2016

📌 Commit a56a7ba has been approved by emilio

@highfive highfive assigned emilio and unassigned mbrubeck Dec 23, 2016
@bors-servo
Copy link
Contributor

bors-servo commented Dec 23, 2016

Testing commit a56a7ba with merge 5fa80ae...

bors-servo added a commit that referenced this pull request Dec 23, 2016
<!-- Please describe your changes on the following line: -->
Add check for bad ports to http_fetch(), return NetworkError::Internal if bad port/schema combination is seen.

Test added

---
<!-- 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 #14514 (github issue number if applicable).

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

<!-- 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/14623)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Dec 23, 2016

💔 Test failed - mac-rel-wpt1

@emilio
Copy link
Member

emilio commented Dec 23, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Dec 23, 2016

Testing commit a56a7ba with merge fd01e7a...

bors-servo added a commit that referenced this pull request Dec 23, 2016
<!-- Please describe your changes on the following line: -->
Add check for bad ports to http_fetch(), return NetworkError::Internal if bad port/schema combination is seen.

Test added

---
<!-- 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 #14514 (github issue number if applicable).

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

<!-- 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/14623)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Dec 23, 2016

💔 Test failed - mac-rel-css

@KiChjang
Copy link
Member

KiChjang commented Dec 23, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Dec 23, 2016

Previous build results for android, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-wpt2, windows-gnu-dev are reusable. Rebuilding only arm32, mac-rel-css, mac-rel-wpt1...

@Ms2ger
Copy link
Contributor

Ms2ger commented Dec 23, 2016

@bors-servo force

@Ms2ger
Copy link
Contributor

Ms2ger commented Dec 23, 2016

Closing for just a moment

@Ms2ger Ms2ger closed this Dec 23, 2016
@Ms2ger Ms2ger reopened this Dec 23, 2016
@bors-servo
Copy link
Contributor

bors-servo commented Dec 24, 2016

💥 Test timed out

@KiChjang
Copy link
Member

KiChjang commented Dec 24, 2016

@bors-servo retry

@bors-servo
Copy link
Contributor

bors-servo commented Dec 24, 2016

Testing commit a56a7ba with merge de7d73a...

bors-servo added a commit that referenced this pull request Dec 24, 2016
<!-- Please describe your changes on the following line: -->
Add check for bad ports to http_fetch(), return NetworkError::Internal if bad port/schema combination is seen.

Test added

---
<!-- 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 #14514 (github issue number if applicable).

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

<!-- 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/14623)
<!-- Reviewable:end -->
@bors-servo bors-servo merged commit a56a7ba into servo:master Dec 24, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@bors-servo bors-servo mentioned this pull request Dec 24, 2016
4 of 4 tasks complete
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.

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