Auto merge of #14623 - DominoTree:master, r=emilio

<!-- 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 -->
This commit is contained in:
bors-servo 2016-12-24 03:41:14 -08:00 committed by GitHub
commit de7d73adb0
4 changed files with 113 additions and 0 deletions

View file

@ -143,6 +143,18 @@ pub fn main_fetch(request: Rc<Request>,
// Step 5
// TODO this step (CSP port/content blocking)
if let Some(port) = request.url().port() {
let is_ftp = request.url().scheme() == "ftp" && (port == 20 || port == 21);
static BAD_PORTS: [u16; 64] = [1, 7, 9, 11, 13, 15, 17, 19, 20, 21, 22, 23, 25, 37, 42,
43, 53, 77, 79, 87, 95, 101, 102, 103, 104, 109, 110, 111,
113, 115, 117, 119, 123, 135, 139, 143, 179, 389, 465, 512,
513, 514, 515, 526, 530, 531, 532, 540, 556, 563, 587, 601,
636, 993, 995, 2049, 3659, 4045, 6000, 6665, 6666, 6667,
6668, 6669];
if !is_ftp && BAD_PORTS.binary_search(&port).is_ok() {
response = Some(Response::network_error(NetworkError::Internal("Request attempted on bad port".into())));
}
}
// Step 6
// TODO this step (referrer policy)