Skip to content

Commit 166b4de

Browse files
author
bors-servo
authored
Auto merge of #14623 - DominoTree:master, r=<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 -->
2 parents 8412008 + dfdf0e9 commit 166b4de

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

components/net/http_loader.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,23 @@ pub fn http_fetch(request: Rc<Request>,
537537
done_chan: &mut DoneChannel,
538538
context: &FetchContext)
539539
-> Response {
540+
// Bad port blocking - https://fetch.spec.whatwg.org/#block-bad-port
541+
match request.url().port() {
542+
Some(port) => {
543+
let is_ftp: bool = request.url().scheme() == "ftp" && (port == 20 || port == 21);
544+
let bad_ports: Vec<u16> = vec![1, 7, 9, 11, 13, 15, 17, 19, 20, 21, 22, 23, 25, 37, 42,
545+
43, 53, 77, 79, 87, 95, 101, 102, 103, 104, 109, 110,
546+
111, 113, 115, 117, 119, 123, 135, 139, 143, 179, 389,
547+
465, 512, 513, 514, 515, 526, 530, 531, 532, 540, 556,
548+
563, 587, 601, 636, 993, 995, 2049, 3659, 4045, 6000,
549+
6665, 6666, 6667, 6668, 6669];
550+
if !is_ftp && bad_ports.contains(&port) {
551+
return Response::network_error(NetworkError::BadPort);
552+
}
553+
},
554+
None => {}
555+
}
556+
540557
// This is a new async fetch, reset the channel we are waiting on
541558
*done_chan = None;
542559
// Step 1

components/net_traits/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,8 @@ pub enum ConstellationMsg {
525525
/// Network errors that have to be exported out of the loaders
526526
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize, HeapSizeOf)]
527527
pub enum NetworkError {
528+
/// Request attempted on bad port - https://fetch.spec.whatwg.org/#block-bad-port
529+
BadPort,
528530
/// Could be any of the internal errors, like unsupported scheme, connection errors, etc.
529531
Internal(String),
530532
LoadCancelled,

tests/unit/net/fetch.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use hyper::status::StatusCode;
2323
use hyper::uri::RequestUri;
2424
use msg::constellation_msg::TEST_PIPELINE_ID;
2525
use net::fetch::cors_cache::CorsCache;
26+
use net_traits::NetworkError;
2627
use net_traits::ReferrerPolicy;
2728
use net_traits::request::{Origin, RedirectMode, Referrer, Request, RequestMode};
2829
use net_traits::response::{CacheState, Response, ResponseBody, ResponseType};
@@ -59,6 +60,18 @@ fn test_fetch_response_is_not_network_error() {
5960
}
6061
}
6162

63+
#[test]
64+
fn test_fetch_on_bad_port_is_network_error() {
65+
let url = ServoUrl::parse("http://www.example.org:6667").unwrap();
66+
let origin = Origin::Origin(url.origin());
67+
let request = Request::new(url, Some(origin), false, None);
68+
*request.referrer.borrow_mut() = Referrer::NoReferrer;
69+
let fetch_response = fetch(request, None);
70+
assert!(fetch_response.is_network_error());
71+
let fetch_error = fetch_response.get_network_error().unwrap();
72+
assert!(fetch_error == &NetworkError::BadPort)
73+
}
74+
6275
#[test]
6376
fn test_fetch_response_body_matches_const_message() {
6477
static MESSAGE: &'static [u8] = b"Hello World!";

0 commit comments

Comments
 (0)