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

Side by Side Diff: net/cookies/cookie_util.cc

Issue 1414603010: Treat exact domain match cookies on public suffixes as host cookies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test. Created 5 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 | « net/cookies/cookie_store_unittest.h ('k') | no next file » | 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/cookies/cookie_util.h" 5 #include "net/cookies/cookie_util.h"
6 6
7 #include <cstdio> 7 #include <cstdio>
8 #include <cstdlib> 8 #include <cstdlib>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 std::string cookie_domain(CanonicalizeHost(domain_string, &ignored)); 56 std::string cookie_domain(CanonicalizeHost(domain_string, &ignored));
57 if (cookie_domain.empty()) 57 if (cookie_domain.empty())
58 return false; 58 return false;
59 if (cookie_domain[0] != '.') 59 if (cookie_domain[0] != '.')
60 cookie_domain = "." + cookie_domain; 60 cookie_domain = "." + cookie_domain;
61 61
62 // Ensure |url| and |cookie_domain| have the same domain+registry. 62 // Ensure |url| and |cookie_domain| have the same domain+registry.
63 const std::string url_scheme(url.scheme()); 63 const std::string url_scheme(url.scheme());
64 const std::string url_domain_and_registry( 64 const std::string url_domain_and_registry(
65 GetEffectiveDomain(url_scheme, url_host)); 65 GetEffectiveDomain(url_scheme, url_host));
66 if (url_domain_and_registry.empty()) 66 if (url_domain_and_registry.empty()) {
67 return false; // IP addresses/intranet hosts can't set domain cookies. 67 // We match IE/Firefox by treating an exact match between the domain
68 // attribute and the request host to be treated as a host cookie.
69 if (url_host == domain_string) {
70 *result = url_host;
71 DCHECK(DomainIsHostOnly(*result));
72 return true;
73 }
74
75 // Otherwise, IP addresses/intranet hosts/public suffixes can't set
76 // domain cookies.
77 return false;
78 }
68 const std::string cookie_domain_and_registry( 79 const std::string cookie_domain_and_registry(
69 GetEffectiveDomain(url_scheme, cookie_domain)); 80 GetEffectiveDomain(url_scheme, cookie_domain));
70 if (url_domain_and_registry != cookie_domain_and_registry) 81 if (url_domain_and_registry != cookie_domain_and_registry)
71 return false; // Can't set a cookie on a different domain + registry. 82 return false; // Can't set a cookie on a different domain + registry.
72 83
73 // Ensure |url_host| is |cookie_domain| or one of its subdomains. Given that 84 // Ensure |url_host| is |cookie_domain| or one of its subdomains. Given that
74 // we know the domain+registry are the same from the above checks, this is 85 // we know the domain+registry are the same from the above checks, this is
75 // basically a simple string suffix check. 86 // basically a simple string suffix check.
76 const bool is_suffix = (url_host.length() < cookie_domain.length()) ? 87 const bool is_suffix = (url_host.length() < cookie_domain.length()) ?
77 (cookie_domain != ("." + url_host)) : 88 (cookie_domain != ("." + url_host)) :
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 buffer.append("; "); 273 buffer.append("; ");
263 buffer.append(i->first.begin(), i->first.end()); 274 buffer.append(i->first.begin(), i->first.end());
264 buffer.push_back('='); 275 buffer.push_back('=');
265 buffer.append(i->second.begin(), i->second.end()); 276 buffer.append(i->second.begin(), i->second.end());
266 } 277 }
267 return buffer; 278 return buffer;
268 } 279 }
269 280
270 } // namespace cookie_util 281 } // namespace cookie_util
271 } // namespace net 282 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/cookie_store_unittest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698