#14514 Implement port-based blocking#14623
#14514 Implement port-based blocking#14623bors-servo merged 1 commit intoservo:masterfrom DominoTree:master
Conversation
|
Heads up! This PR modifies the following files:
|
components/net/http_loader.rs
Outdated
| 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, |
There was a problem hiding this comment.
This can be a static array, and you can binary-search on it for speed.
components/net/http_loader.rs
Outdated
| // 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); |
There was a problem hiding this comment.
I think the type annotation (: bool) is not needed, is it?
There was a problem hiding this comment.
Just added this because it made things a bit clearer for me, but it's definitely not needed.
components/net/http_loader.rs
Outdated
| context: &FetchContext) | ||
| -> Response { | ||
| // Bad port blocking - https://fetch.spec.whatwg.org/#block-bad-port | ||
| match request.url().port() { |
There was a problem hiding this comment.
Given the None arm is empty, you can do:
if let Some(port) = request.url.port() {
// ...
}| } | ||
| } | ||
|
|
||
| #[test] |
There was a problem hiding this comment.
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 -->
|
☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css, mac-rel-wpt1, mac-rel-wpt2, windows-dev |
components/net_traits/lib.rs
Outdated
| #[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, |
There was a problem hiding this comment.
I don't think it's particularly useful to introduce a new variant here; Internal will be fine.
There was a problem hiding this comment.
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([ |
There was a problem hiding this comment.
No need for Promise.all here; we can simply use return promise_rejects(...).
There was a problem hiding this comment.
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! :) |
|
📌 Commit a56a7ba has been approved by |
<!-- 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 -->
|
💔 Test failed - mac-rel-wpt1 |
|
@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 -->
|
💔 Test failed - mac-rel-css |
|
⚡ 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... |
|
@bors-servo force |
|
Closing for just a moment |
|
💥 Test timed out |
|
@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 -->
|
☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css, mac-rel-wpt1, mac-rel-wpt2, windows-gnu-dev, windows-msvc-dev |
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