Skip to content

#14514 Implement port-based blocking#14623

Merged
bors-servo merged 1 commit intoservo:masterfrom
DominoTree:master
Dec 24, 2016
Merged

#14514 Implement port-based blocking#14623
bors-servo merged 1 commit intoservo:masterfrom
DominoTree:master

Conversation

@DominoTree
Copy link
Copy Markdown
Contributor

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


  • There are tests for these changes OR

This change is Reviewable

@highfive
Copy link
Copy Markdown

Heads up! This PR modifies the following files:

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Dec 17, 2016
@DominoTree DominoTree closed this Dec 18, 2016
@DominoTree DominoTree reopened this Dec 18, 2016
Copy link
Copy Markdown
Member

@emilio emilio left a comment

Choose a reason for hiding this comment

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

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,
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 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);
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 think the type annotation (: bool) is not needed, is it?

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.

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

context: &FetchContext)
-> Response {
// Bad port blocking - https://fetch.spec.whatwg.org/#block-bad-port
match request.url().port() {
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.

Given the None arm is empty, you can do:

if let Some(port) = request.url.port() {
    // ...
}

}
}

#[test]
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.

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

@emilio
Copy link
Copy Markdown
Member

emilio commented Dec 19, 2016

@bors-servo try

@bors-servo
Copy link
Copy Markdown
Contributor

⌛ Trying commit dfdf0e9 with merge 166b4de...

bors-servo pushed 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
Copy Markdown
Contributor

#[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,
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.

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

Copy link
Copy Markdown
Contributor Author

@DominoTree DominoTree Dec 19, 2016

Choose a reason for hiding this comment

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

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

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

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

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.

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
Copy Markdown
Contributor Author

Think that should do it!

@Ms2ger
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

emilio commented Dec 23, 2016

@bors-servo r+

Thanks! :)

@bors-servo
Copy link
Copy Markdown
Contributor

📌 Commit a56a7ba has been approved by emilio

@highfive highfive assigned emilio and unassigned mbrubeck Dec 23, 2016
@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 23, 2016
@bors-servo
Copy link
Copy Markdown
Contributor

⌛ Testing commit a56a7ba with merge 5fa80ae...

bors-servo pushed 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
Copy Markdown
Contributor

💔 Test failed - mac-rel-wpt1

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Dec 23, 2016
@emilio
Copy link
Copy Markdown
Member

emilio commented Dec 23, 2016

@bors-servo retry servo/saltfs#565

@bors-servo
Copy link
Copy Markdown
Contributor

⌛ Testing commit a56a7ba with merge fd01e7a...

bors-servo pushed 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 -->
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Dec 23, 2016
@bors-servo
Copy link
Copy Markdown
Contributor

💔 Test failed - mac-rel-css

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Dec 23, 2016
@KiChjang
Copy link
Copy Markdown
Contributor

@bors-servo
Copy link
Copy Markdown
Contributor

⚡ 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
Copy Markdown
Contributor

Ms2ger commented Dec 23, 2016

@bors-servo force

@Ms2ger
Copy link
Copy Markdown
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
Copy Markdown
Contributor

💥 Test timed out

@KiChjang
Copy link
Copy Markdown
Contributor

@bors-servo retry

@bors-servo
Copy link
Copy Markdown
Contributor

⌛ Testing commit a56a7ba with merge de7d73a...

bors-servo pushed 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 -->
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Dec 24, 2016
@bors-servo
Copy link
Copy Markdown
Contributor

@bors-servo bors-servo merged commit a56a7ba into servo:master Dec 24, 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 24, 2016
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 port-based blocking

8 participants