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

Side by Side Diff: net/proxy/proxy_bypass_rules.cc

Issue 1831653002: Don't allow a leading plus in ports for proxy bypass rules. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 9 months 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 | « no previous file | net/proxy/proxy_bypass_rules_unittest.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/proxy/proxy_bypass_rules.h" 5 #include "net/proxy/proxy_bypass_rules.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "base/strings/pattern.h" 8 #include "base/strings/pattern.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_piece.h" 9 #include "base/strings/string_piece.h"
11 #include "base/strings/string_tokenizer.h" 10 #include "base/strings/string_tokenizer.h"
12 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
14 #include "net/base/host_port_pair.h" 13 #include "net/base/host_port_pair.h"
15 #include "net/base/ip_address.h" 14 #include "net/base/ip_address.h"
15 #include "net/base/parse_number.h"
16 #include "net/base/url_util.h" 16 #include "net/base/url_util.h"
17 17
18 namespace net { 18 namespace net {
19 19
20 namespace { 20 namespace {
21 21
22 class HostnamePatternRule : public ProxyBypassRules::Rule { 22 class HostnamePatternRule : public ProxyBypassRules::Rule {
23 public: 23 public:
24 HostnamePatternRule(const std::string& optional_scheme, 24 HostnamePatternRule(const std::string& optional_scheme,
25 const std::string& hostname_pattern, 25 const std::string& hostname_pattern,
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 std::string bracketed_host = HostPortPair(host, 80).HostForURL(); 310 std::string bracketed_host = HostPortPair(host, 80).HostForURL();
311 if (IsIPAddress(bracketed_host)) { 311 if (IsIPAddress(bracketed_host)) {
312 // Canonicalize the IP literal before adding it as a string pattern. 312 // Canonicalize the IP literal before adding it as a string pattern.
313 GURL tmp_url("http://" + bracketed_host); 313 GURL tmp_url("http://" + bracketed_host);
314 return AddRuleForHostname(scheme, tmp_url.host(), port); 314 return AddRuleForHostname(scheme, tmp_url.host(), port);
315 } 315 }
316 } 316 }
317 317
318 // Otherwise assume we have <hostname-pattern>[:port]. 318 // Otherwise assume we have <hostname-pattern>[:port].
319 std::string::size_type pos_colon = raw.rfind(':'); 319 std::string::size_type pos_colon = raw.rfind(':');
320 host = raw;
321 port = -1; 320 port = -1;
322 if (pos_colon != std::string::npos) { 321 if (pos_colon != std::string::npos) {
323 if (!base::StringToInt(base::StringPiece(raw.begin() + pos_colon + 1, 322 if (!ParseNonNegativeDecimalInt(
324 raw.end()), 323 base::StringPiece(raw.begin() + pos_colon + 1, raw.end()), &port) ||
325 &port) || 324 port > 0xFFFF) {
326 (port < 0 || port > 0xFFFF)) {
327 return false; // Port was invalid. 325 return false; // Port was invalid.
328 } 326 }
329 raw = raw.substr(0, pos_colon); 327 raw = raw.substr(0, pos_colon);
330 } 328 }
331 329
332 // Special-case hostnames that begin with a period. 330 // Special-case hostnames that begin with a period.
333 // For example, we remap ".google.com" --> "*.google.com". 331 // For example, we remap ".google.com" --> "*.google.com".
334 if (base::StartsWith(raw, ".", base::CompareCase::SENSITIVE)) 332 if (base::StartsWith(raw, ".", base::CompareCase::SENSITIVE))
335 raw = "*" + raw; 333 raw = "*" + raw;
336 334
337 // If suffix matching was asked for, make sure the pattern starts with a 335 // If suffix matching was asked for, make sure the pattern starts with a
338 // wildcard. 336 // wildcard.
339 if (use_hostname_suffix_matching && 337 if (use_hostname_suffix_matching &&
340 !base::StartsWith(raw, "*", base::CompareCase::SENSITIVE)) 338 !base::StartsWith(raw, "*", base::CompareCase::SENSITIVE))
341 raw = "*" + raw; 339 raw = "*" + raw;
342 340
343 return AddRuleForHostname(scheme, raw, port); 341 return AddRuleForHostname(scheme, raw, port);
344 } 342 }
345 343
346 bool ProxyBypassRules::AddRuleFromStringInternalWithLogging( 344 bool ProxyBypassRules::AddRuleFromStringInternalWithLogging(
347 const std::string& raw, 345 const std::string& raw,
348 bool use_hostname_suffix_matching) { 346 bool use_hostname_suffix_matching) {
349 return AddRuleFromStringInternal(raw, use_hostname_suffix_matching); 347 return AddRuleFromStringInternal(raw, use_hostname_suffix_matching);
350 } 348 }
351 349
352 } // namespace net 350 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/proxy/proxy_bypass_rules_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698