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

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

Issue 2158863003: Fix CanonicalCookie::IsEquivalentForSecureCookieMatching (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 | « net/cookies/canonical_cookie.h ('k') | net/cookies/cookie_monster.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 // Portions of this code based on Mozilla: 5 // Portions of this code based on Mozilla:
6 // (netwerk/cookie/src/nsCookieService.cpp) 6 // (netwerk/cookie/src/nsCookieService.cpp)
7 /* ***** BEGIN LICENSE BLOCK ***** 7 /* ***** BEGIN LICENSE BLOCK *****
8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
9 * 9 *
10 * The contents of this file are subject to the Mozilla Public License Version 10 * The contents of this file are subject to the Mozilla Public License Version
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 const std::string& value, 130 const std::string& value,
131 const std::string& domain, 131 const std::string& domain,
132 const std::string& path, 132 const std::string& path,
133 const base::Time& creation, 133 const base::Time& creation,
134 const base::Time& expiration, 134 const base::Time& expiration,
135 const base::Time& last_access, 135 const base::Time& last_access,
136 bool secure, 136 bool secure,
137 bool httponly, 137 bool httponly,
138 CookieSameSite same_site, 138 CookieSameSite same_site,
139 CookiePriority priority) 139 CookiePriority priority)
140 : source_(url.SchemeIsFile() ? url : url.GetOrigin()), 140 : name_(name),
141 name_(name),
142 value_(value), 141 value_(value),
143 domain_(domain), 142 domain_(domain),
144 path_(path), 143 path_(path),
145 creation_date_(creation), 144 creation_date_(creation),
146 expiry_date_(expiration), 145 expiry_date_(expiration),
147 last_access_date_(last_access), 146 last_access_date_(last_access),
148 secure_(secure), 147 secure_(secure),
149 httponly_(httponly), 148 httponly_(httponly),
150 same_site_(same_site), 149 same_site_(same_site),
151 priority_(priority) {} 150 priority_(priority) {}
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 const base::Time& last_access, 320 const base::Time& last_access,
322 bool secure, 321 bool secure,
323 bool http_only, 322 bool http_only,
324 CookieSameSite same_site, 323 CookieSameSite same_site,
325 CookiePriority priority) { 324 CookiePriority priority) {
326 return base::WrapUnique(new CanonicalCookie( 325 return base::WrapUnique(new CanonicalCookie(
327 GURL(), name, value, domain, path, creation, expiration, last_access, 326 GURL(), name, value, domain, path, creation, expiration, last_access,
328 secure, http_only, same_site, priority)); 327 secure, http_only, same_site, priority));
329 } 328 }
330 329
330 bool CanonicalCookie::IsEquivalentForSecureCookieMatching(
331 const CanonicalCookie& ecc) const {
332 return (name_ == ecc.Name() && (ecc.IsDomainMatch(DomainWithoutDot()) ||
333 IsDomainMatch(ecc.DomainWithoutDot())));
334 }
335
331 bool CanonicalCookie::IsOnPath(const std::string& url_path) const { 336 bool CanonicalCookie::IsOnPath(const std::string& url_path) const {
332 337
333 // A zero length would be unsafe for our trailing '/' checks, and 338 // A zero length would be unsafe for our trailing '/' checks, and
334 // would also make no sense for our prefix match. The code that 339 // would also make no sense for our prefix match. The code that
335 // creates a CanonicalCookie should make sure the path is never zero length, 340 // creates a CanonicalCookie should make sure the path is never zero length,
336 // but we double check anyway. 341 // but we double check anyway.
337 if (path_.empty()) 342 if (path_.empty())
338 return false; 343 return false;
339 344
340 // The Mozilla code broke this into three cases, based on if the cookie path 345 // The Mozilla code broke this into three cases, based on if the cookie path
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 const ParsedCookie& parsed_cookie) { 516 const ParsedCookie& parsed_cookie) {
512 if (prefix == CanonicalCookie::COOKIE_PREFIX_SECURE) 517 if (prefix == CanonicalCookie::COOKIE_PREFIX_SECURE)
513 return parsed_cookie.IsSecure() && url.SchemeIsCryptographic(); 518 return parsed_cookie.IsSecure() && url.SchemeIsCryptographic();
514 if (prefix == CanonicalCookie::COOKIE_PREFIX_HOST) { 519 if (prefix == CanonicalCookie::COOKIE_PREFIX_HOST) {
515 return parsed_cookie.IsSecure() && url.SchemeIsCryptographic() && 520 return parsed_cookie.IsSecure() && url.SchemeIsCryptographic() &&
516 !parsed_cookie.HasDomain() && parsed_cookie.Path() == "/"; 521 !parsed_cookie.HasDomain() && parsed_cookie.Path() == "/";
517 } 522 }
518 return true; 523 return true;
519 } 524 }
520 525
526 std::string CanonicalCookie::DomainWithoutDot() const {
527 if (domain_.empty() || domain_[0] != '.')
528 return domain_;
529 return domain_.substr(1);
530 }
531
521 } // namespace net 532 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/canonical_cookie.h ('k') | net/cookies/cookie_monster.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698