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

Side by Side Diff: components/google/core/browser/google_util.cc

Issue 2498113003: Add verification that google URL has a valid TLD. (Closed)
Patch Set: Created 4 years, 1 month 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 | components/google/core/browser/google_util_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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/google/core/browser/google_util.h" 5 #include "components/google/core/browser/google_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 20 matching lines...) Expand all
31 #else 31 #else
32 #define LINKDOCTOR_SERVER_REQUEST_URL "" 32 #define LINKDOCTOR_SERVER_REQUEST_URL ""
33 #endif 33 #endif
34 34
35 namespace google_util { 35 namespace google_util {
36 36
37 // Helpers -------------------------------------------------------------------- 37 // Helpers --------------------------------------------------------------------
38 38
39 namespace { 39 namespace {
40 40
41 // TODO(mariakhomenko): figure out how to keep this list updated.
42 static const char* const g_google_tld_list[] = {"ac", "ad", "ae", "af", "ag",
Peter Kasting 2016/11/15 22:11:56 Nit: constexpr If this remains used by only one f
Maria 2016/11/15 23:36:31 Switched to constexpr.
43 "al", "am", "as", "at", "aw", "az", "ba", "be", "bf", "bg", "bi", "biz",
44 "bj", "bm", "bn", "bo", "bs", "bt", "by", "bz", "ca", "cat", "cc", "cd",
45 "cf", "cg", "ch", "ci", "cl", "cm", "cn", "co", "co.ao", "co.at", "co.ba",
46 "co.bi", "co.bw", "co.ci", "co.ck", "co.cr", "co.gg", "co.gl", "co.gy",
47 "co.hu", "co.id", "co.il", "co.im", "co.in", "co.it", "co.je", "co.jp",
48 "co.ke", "co.kr", "co.ls", "co.ma", "co.mu", "co.mw", "co.mz", "co.nz",
49 "co.pn", "co.rs", "co.th", "co.tt", "co.tz", "co.ua", "co.ug", "co.uk",
50 "co.uz", "co.ve", "co.vi", "co.za", "co.zm", "co.zw", "com", "com.af",
51 "com.ag", "com.ai", "com.ar", "com.au", "com.az", "com.bd", "com.bh",
52 "com.bi", "com.bn", "com.bo", "com.br", "com.bs", "com.by", "com.bz",
53 "com.cn", "com.co", "com.cu", "com.cy", "com.do", "com.dz", "com.ec",
54 "com.eg", "com.er", "com.et", "com.fj", "com.ge", "com.gh", "com.gi",
55 "com.gl", "com.gp", "com.gr", "com.gt", "com.gy", "com.hk", "com.hn",
56 "com.hr", "com.ht", "com.iq", "com.jm", "com.jo", "com.kg", "com.kh",
57 "com.ki", "com.kw", "com.kz", "com.lb", "com.lc", "com.lk", "com.lv",
58 "com.ly", "com.mk", "com.mm", "com.mt", "com.mu", "com.mw", "com.mx",
59 "com.my", "com.na", "com.nc", "com.nf", "com.ng", "com.ni", "com.np",
60 "com.nr", "com.om", "com.pa", "com.pe", "com.pg", "com.ph", "com.pk",
61 "com.pl", "com.pr", "com.ps", "com.pt", "com.py", "com.qa", "com.ru",
62 "com.sa", "com.sb", "com.sc", "com.sg", "com.sl", "com.sv", "com.tj",
63 "com.tm", "com.tn", "com.tr", "com.tt", "com.tw", "com.ua", "com.uy",
64 "com.uz", "com.vc", "com.ve", "com.vi", "com.vn", "com.ws", "cv", "cx",
65 "cz", "de", "dj", "dk", "dm", "do", "dz", "ec", "ee", "es", "eu", "fi",
66 "fm", "fr", "ga", "gd", "ge", "gf", "gg", "gl", "gm", "gp", "gr", "gw",
67 "gy", "hk", "hn", "hr", "ht", "hu", "ie", "im", "in", "info", "in.rs", "io",
68 "iq", "is", "it", "it.ao", "je", "jo", "jobs", "jp", "kg", "ki", "kids.us",
69 "km", "kn", "kr", "kz", "la", "li", "lk", "lt", "lu", "lv", "ma", "md",
70 "me", "mg", "mh", "mk", "ml", "mn", "mobi", "mr", "ms", "mu", "mv", "mw",
71 "mx", "name", "ne", "ne.jp", "net", "net.in", "net.nz", "nf", "ng", "nl",
72 "no", "nom.es", "nr", "nu", "off.ai", "org", "org.af", "org.es", "org.in",
73 "org.nz", "org.uk", "pf", "ph", "pk", "pl", "pn", "pr", "pro", "ps", "pt",
74 "qa", "re", "ro", "rs", "ru", "rw", "sc", "se", "sg", "sh", "si", "sk",
75 "sl", "sm", "sn", "so", "sr", "st", "sz", "td", "tel", "tg", "tk", "tl",
76 "tm", "tn", "to", "tt", "tv", "tw", "ua", "ug", "us", "uz", "vc", "vg",
77 "vn", "vu", "ws", "yt"};
78
41 bool gUseMockLinkDoctorBaseURLForTesting = false; 79 bool gUseMockLinkDoctorBaseURLForTesting = false;
42 80
43 bool IsPathHomePageBase(base::StringPiece path) { 81 bool IsPathHomePageBase(base::StringPiece path) {
44 return (path == "/") || (path == "/webhp"); 82 return (path == "/") || (path == "/webhp");
45 } 83 }
46 84
47 // True if the given canonical |host| is "[www.]<domain_in_lower_case>.<TLD>" 85 // True if the given canonical |host| is "[www.]<domain_in_lower_case>.<TLD>"
48 // with a valid TLD. If |subdomain_permission| is ALLOW_SUBDOMAIN, we check 86 // with a valid TLD. If |subdomain_permission| is ALLOW_SUBDOMAIN, we check
49 // against host "*.<domain_in_lower_case>.<TLD>" instead. 87 // against host "*.<domain_in_lower_case>.<TLD>" instead.
50 bool IsValidHostName(base::StringPiece host, 88 bool IsValidHostName(base::StringPiece host,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 return url.is_valid() && url.SchemeIsHTTPOrHTTPS() && 120 return url.is_valid() && url.SchemeIsHTTPOrHTTPS() &&
83 (url.port().empty() || (port_permission == ALLOW_NON_STANDARD_PORTS)); 121 (url.port().empty() || (port_permission == ALLOW_NON_STANDARD_PORTS));
84 } 122 }
85 123
86 bool IsCanonicalHostGoogleHostname(base::StringPiece canonical_host, 124 bool IsCanonicalHostGoogleHostname(base::StringPiece canonical_host,
87 SubdomainPermission subdomain_permission) { 125 SubdomainPermission subdomain_permission) {
88 const GURL& base_url(CommandLineGoogleBaseURL()); 126 const GURL& base_url(CommandLineGoogleBaseURL());
89 if (base_url.is_valid() && (canonical_host == base_url.host_piece())) 127 if (base_url.is_valid() && (canonical_host == base_url.host_piece()))
90 return true; 128 return true;
91 129
92 return IsValidHostName(canonical_host, "google", subdomain_permission); 130 bool valid = IsValidHostName(canonical_host, "google", subdomain_permission);
131 if (!valid)
132 return valid;
133
134 // Validate that we have a TLD that Google has registered.
135 size_t tld_length =
136 net::registry_controlled_domains::GetCanonicalHostRegistryLength(
Peter Kasting 2016/11/15 22:11:56 This implementation computes the registry length (
Maria 2016/11/15 23:36:31 Done -- switched to return tld from IsValidHostNam
137 canonical_host,
138 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES,
139 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
140
141 base::StringPiece tld(
142 canonical_host.substr(canonical_host.length() - tld_length,
143 base::StringPiece::npos));
144 for (size_t i = 0; g_google_tld_list[i]; i++) {
145 if (g_google_tld_list[i] == tld) {
146 return true;
147 }
148 }
149 return false;
Peter Kasting 2016/11/15 22:11:57 This linear search is less-efficient than it could
Maria 2016/11/15 23:36:31 Agree. I was thinking about that. The reason I wen
Peter Kasting 2016/11/15 23:46:50 CR_DEFINE_STATIC_LOCAL within the function is the
93 } 150 }
94 151
95 } // namespace 152 } // namespace
96 153
97 // Global functions ----------------------------------------------------------- 154 // Global functions -----------------------------------------------------------
98 155
99 bool HasGoogleSearchQueryParam(base::StringPiece str) { 156 bool HasGoogleSearchQueryParam(base::StringPiece str) {
100 url::Component query(0, static_cast<int>(str.length())), key, value; 157 url::Component query(0, static_cast<int>(str.length())), key, value;
101 while (url::ExtractQueryKeyValue(str.data(), &query, &key, &value)) { 158 while (url::ExtractQueryKeyValue(str.data(), &query, &key, &value)) {
102 if (value.is_nonempty()) { 159 if (value.is_nonempty()) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 284 }
228 285
229 bool IsYoutubeDomainUrl(const GURL& url, 286 bool IsYoutubeDomainUrl(const GURL& url,
230 SubdomainPermission subdomain_permission, 287 SubdomainPermission subdomain_permission,
231 PortPermission port_permission) { 288 PortPermission port_permission) {
232 return IsValidURL(url, port_permission) && 289 return IsValidURL(url, port_permission) &&
233 IsValidHostName(url.host_piece(), "youtube", subdomain_permission); 290 IsValidHostName(url.host_piece(), "youtube", subdomain_permission);
234 } 291 }
235 292
236 } // namespace google_util 293 } // namespace google_util
OLDNEW
« no previous file with comments | « no previous file | components/google/core/browser/google_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698