Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: net/base/net_util.cc

Issue 770343003: Block port 443 for all protocols other than HTTPS or WSS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unit test. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/base/net_util.h ('k') | net/http/http_stream_factory_impl_job.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/base/net_util.h" 5 #include "net/base/net_util.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 113, // auth 100 113, // auth
101 115, // sftp 101 115, // sftp
102 117, // uucp-path 102 117, // uucp-path
103 119, // nntp 103 119, // nntp
104 123, // NTP 104 123, // NTP
105 135, // loc-srv /epmap 105 135, // loc-srv /epmap
106 139, // netbios 106 139, // netbios
107 143, // imap2 107 143, // imap2
108 179, // BGP 108 179, // BGP
109 389, // ldap 109 389, // ldap
110 443, // https / wss
davidben 2014/12/03 20:16:11 Would be good to have a comment or bug reference h
lgarron 2014/12/04 01:16:12 After talking with Chris Palmer/Mike West, I'm goi
110 465, // smtp+ssl 111 465, // smtp+ssl
111 512, // print / exec 112 512, // print / exec
112 513, // login 113 513, // login
113 514, // shell 114 514, // shell
114 515, // printer 115 515, // printer
115 526, // tempo 116 526, // tempo
116 530, // courier 117 530, // courier
117 531, // chat 118 531, // chat
118 532, // netnews 119 532, // netnews
119 540, // uucp 120 540, // uucp
(...skipping 17 matching lines...) Expand all
137 // third_party/WebKit/Source/platform/weborigin/KURL.cpp, 138 // third_party/WebKit/Source/platform/weborigin/KURL.cpp,
138 // KURL::port()) 139 // KURL::port())
139 }; 140 };
140 141
141 // FTP overrides the following restricted ports. 142 // FTP overrides the following restricted ports.
142 static const int kAllowedFtpPorts[] = { 143 static const int kAllowedFtpPorts[] = {
143 21, // ftp data 144 21, // ftp data
144 22, // ssh 145 22, // ssh
145 }; 146 };
146 147
148 // HTTPS and WSS override the following restricted port.
149 static const int kAllowedHttpsOrWssPorts[] = {
150 443, // https / wss
151 };
152
147 bool IPNumberPrefixCheck(const IPAddressNumber& ip_number, 153 bool IPNumberPrefixCheck(const IPAddressNumber& ip_number,
148 const unsigned char* ip_prefix, 154 const unsigned char* ip_prefix,
149 size_t prefix_length_in_bits) { 155 size_t prefix_length_in_bits) {
150 // Compare all the bytes that fall entirely within the prefix. 156 // Compare all the bytes that fall entirely within the prefix.
151 int num_entire_bytes_in_prefix = prefix_length_in_bits / 8; 157 int num_entire_bytes_in_prefix = prefix_length_in_bits / 8;
152 for (int i = 0; i < num_entire_bytes_in_prefix; ++i) { 158 for (int i = 0; i < num_entire_bytes_in_prefix; ++i) {
153 if (ip_number[i] != ip_prefix[i]) 159 if (ip_number[i] != ip_prefix[i])
154 return false; 160 return false;
155 } 161 }
156 162
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 int array_size = arraysize(kAllowedFtpPorts); 319 int array_size = arraysize(kAllowedFtpPorts);
314 for (int i = 0; i < array_size; i++) { 320 for (int i = 0; i < array_size; i++) {
315 if (kAllowedFtpPorts[i] == port) { 321 if (kAllowedFtpPorts[i] == port) {
316 return true; 322 return true;
317 } 323 }
318 } 324 }
319 // Port not explicitly allowed by FTP, so return the default restrictions. 325 // Port not explicitly allowed by FTP, so return the default restrictions.
320 return IsPortAllowedByDefault(port); 326 return IsPortAllowedByDefault(port);
321 } 327 }
322 328
329 bool IsPortAllowedByHttpsOrWss(int port) {
330 int array_size = arraysize(kAllowedHttpsOrWssPorts);
331 for (int i = 0; i < array_size; i++) {
332 if (kAllowedHttpsOrWssPorts[i] == port) {
333 return true;
davidben 2014/12/03 20:16:11 Nit: 2 spaces.
334 }
335 }
336 // Port not explicitly allowed by HTTPS or WSS, so return the default
337 // restrictions.
338 return IsPortAllowedByDefault(port);
339 }
340
341 bool IsEffectivePortAllowedByScheme(const GURL& url) {
342 int port = url.EffectiveIntPort();
343 if (url.SchemeIs("ftp")) {
344 return IsPortAllowedByFtp(port);
345 } else if (url.SchemeIs("https") || url.SchemeIs("wss")) {
346 return IsPortAllowedByHttpsOrWss(port);
347 } else {
348 return IsPortAllowedByDefault(port);
349 }
350 }
351
323 bool IsPortAllowedByOverride(int port) { 352 bool IsPortAllowedByOverride(int port) {
324 if (g_explicitly_allowed_ports.Get().empty()) 353 if (g_explicitly_allowed_ports.Get().empty())
325 return false; 354 return false;
326 355
327 return g_explicitly_allowed_ports.Get().count(port) > 0; 356 return g_explicitly_allowed_ports.Get().count(port) > 0;
328 } 357 }
329 358
330 int SetNonBlocking(int fd) { 359 int SetNonBlocking(int fd) {
331 #if defined(OS_WIN) 360 #if defined(OS_WIN)
332 unsigned long no_block = 1; 361 unsigned long no_block = 1;
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 1085
1057 unsigned MaskPrefixLength(const IPAddressNumber& mask) { 1086 unsigned MaskPrefixLength(const IPAddressNumber& mask) {
1058 IPAddressNumber all_ones(mask.size(), 0xFF); 1087 IPAddressNumber all_ones(mask.size(), 0xFF);
1059 return CommonPrefixLength(mask, all_ones); 1088 return CommonPrefixLength(mask, all_ones);
1060 } 1089 }
1061 1090
1062 ScopedWifiOptions::~ScopedWifiOptions() { 1091 ScopedWifiOptions::~ScopedWifiOptions() {
1063 } 1092 }
1064 1093
1065 } // namespace net 1094 } // namespace net
OLDNEW
« no previous file with comments | « net/base/net_util.h ('k') | net/http/http_stream_factory_impl_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698