Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign up#14514 Implement port-based blocking #14623
Conversation
highfive
commented
Dec 17, 2016
|
Heads up! This PR modifies the following files:
|
| 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.
This comment has been minimized.
| // 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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
emilio
Dec 19, 2016
Member
Any chance we can write this down also as a web platform test (if it doesn't exist)?
|
@bors-servo try |
<!-- 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 -->
|
|
| @@ -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.
This comment has been minimized.
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.
This comment has been minimized.
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.
|
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 Thanks again! :) |
|
Thanks! I think using |
|
@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.
This comment has been minimized.
jdm
Dec 21, 2016
Member
No need for Promise.all here; we can simply use return promise_rejects(...).
This comment has been minimized.
This comment has been minimized.
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.
|
Think that should do it! |
|
Test looks great, but I'm a little surprised you put the code in |
|
@Ms2ger My bad, I overlooked that in the spec. I've moved it into the proper place. |
|
@bors-servo r+ Thanks! :) |
|
|
<!-- 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 retry servo/saltfs#565 |
<!-- 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 retry |
|
|
|
@bors-servo force |
|
Closing for just a moment |
|
|
|
@bors-servo retry |
<!-- 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 -->
|
|
DominoTree commentedDec 17, 2016
•
edited
Add check for bad ports to http_fetch(), return NetworkError::Internal if bad port/schema combination is seen.
Test added
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is