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

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

Issue 1393193005: Implement $Secure- cookie prefix (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove ContentBrowserClient method Created 5 years, 2 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/cookie_monster.h ('k') | net/cookies/cookie_monster_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) 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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 return cookie_line; 324 return cookie_line;
325 } 325 }
326 326
327 void RunAsync(scoped_refptr<base::TaskRunner> proxy, 327 void RunAsync(scoped_refptr<base::TaskRunner> proxy,
328 const CookieStore::CookieChangedCallback& callback, 328 const CookieStore::CookieChangedCallback& callback,
329 const CanonicalCookie& cookie, 329 const CanonicalCookie& cookie,
330 bool removed) { 330 bool removed) {
331 proxy->PostTask(FROM_HERE, base::Bind(callback, cookie, removed)); 331 proxy->PostTask(FROM_HERE, base::Bind(callback, cookie, removed));
332 } 332 }
333 333
334 bool CheckCookiePrefix(CanonicalCookie* cc, const CookieOptions& options) {
335 const char kSecurePrefix[] = "$Secure-";
336 if (cc->Name().find(kSecurePrefix) == 0)
Mike West 2015/10/12 10:59:04 Let's lock this down to CanonicalCookies whose `So
estark 2015/10/12 11:39:43 Done.
337 return cc->IsSecure();
338 return true;
339 }
340
334 } // namespace 341 } // namespace
335 342
336 CookieMonster::CookieMonster(PersistentCookieStore* store, 343 CookieMonster::CookieMonster(PersistentCookieStore* store,
337 CookieMonsterDelegate* delegate) 344 CookieMonsterDelegate* delegate)
338 : initialized_(false), 345 : initialized_(false),
339 started_fetching_all_cookies_(false), 346 started_fetching_all_cookies_(false),
340 finished_fetching_all_cookies_(false), 347 finished_fetching_all_cookies_(false),
341 fetch_strategy_(kUnknownFetch), 348 fetch_strategy_(kUnknownFetch),
342 store_(store), 349 store_(store),
343 last_access_threshold_( 350 last_access_threshold_(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 SetCookieWithDetailsTask(CookieMonster* cookie_monster, 439 SetCookieWithDetailsTask(CookieMonster* cookie_monster,
433 const GURL& url, 440 const GURL& url,
434 const std::string& name, 441 const std::string& name,
435 const std::string& value, 442 const std::string& value,
436 const std::string& domain, 443 const std::string& domain,
437 const std::string& path, 444 const std::string& path,
438 const base::Time& expiration_time, 445 const base::Time& expiration_time,
439 bool secure, 446 bool secure,
440 bool http_only, 447 bool http_only,
441 bool first_party_only, 448 bool first_party_only,
449 bool enforce_prefixes,
442 CookiePriority priority, 450 CookiePriority priority,
443 const SetCookiesCallback& callback) 451 const SetCookiesCallback& callback)
444 : CookieMonsterTask(cookie_monster), 452 : CookieMonsterTask(cookie_monster),
445 url_(url), 453 url_(url),
446 name_(name), 454 name_(name),
447 value_(value), 455 value_(value),
448 domain_(domain), 456 domain_(domain),
449 path_(path), 457 path_(path),
450 expiration_time_(expiration_time), 458 expiration_time_(expiration_time),
451 secure_(secure), 459 secure_(secure),
452 http_only_(http_only), 460 http_only_(http_only),
453 first_party_only_(first_party_only), 461 first_party_only_(first_party_only),
462 enforce_prefixes_(enforce_prefixes),
454 priority_(priority), 463 priority_(priority),
455 callback_(callback) {} 464 callback_(callback) {}
456 465
457 // CookieMonsterTask: 466 // CookieMonsterTask:
458 void Run() override; 467 void Run() override;
459 468
460 protected: 469 protected:
461 ~SetCookieWithDetailsTask() override {} 470 ~SetCookieWithDetailsTask() override {}
462 471
463 private: 472 private:
464 GURL url_; 473 GURL url_;
465 std::string name_; 474 std::string name_;
466 std::string value_; 475 std::string value_;
467 std::string domain_; 476 std::string domain_;
468 std::string path_; 477 std::string path_;
469 base::Time expiration_time_; 478 base::Time expiration_time_;
470 bool secure_; 479 bool secure_;
471 bool http_only_; 480 bool http_only_;
472 bool first_party_only_; 481 bool first_party_only_;
482 bool enforce_prefixes_;
473 CookiePriority priority_; 483 CookiePriority priority_;
474 SetCookiesCallback callback_; 484 SetCookiesCallback callback_;
475 485
476 DISALLOW_COPY_AND_ASSIGN(SetCookieWithDetailsTask); 486 DISALLOW_COPY_AND_ASSIGN(SetCookieWithDetailsTask);
477 }; 487 };
478 488
479 void CookieMonster::SetCookieWithDetailsTask::Run() { 489 void CookieMonster::SetCookieWithDetailsTask::Run() {
480 bool success = this->cookie_monster()->SetCookieWithDetails( 490 bool success = this->cookie_monster()->SetCookieWithDetails(
481 url_, name_, value_, domain_, path_, expiration_time_, secure_, 491 url_, name_, value_, domain_, path_, expiration_time_, secure_,
482 http_only_, first_party_only_, priority_); 492 http_only_, first_party_only_, enforce_prefixes_, priority_);
483 if (!callback_.is_null()) { 493 if (!callback_.is_null()) {
484 this->InvokeCallback(base::Bind(&SetCookiesCallback::Run, 494 this->InvokeCallback(base::Bind(&SetCookiesCallback::Run,
485 base::Unretained(&callback_), success)); 495 base::Unretained(&callback_), success));
486 } 496 }
487 } 497 }
488 498
489 // Task class for GetAllCookies call. 499 // Task class for GetAllCookies call.
490 class CookieMonster::GetAllCookiesTask : public CookieMonsterTask { 500 class CookieMonster::GetAllCookiesTask : public CookieMonsterTask {
491 public: 501 public:
492 GetAllCookiesTask(CookieMonster* cookie_monster, 502 GetAllCookiesTask(CookieMonster* cookie_monster,
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 void CookieMonster::SetCookieWithDetailsAsync( 931 void CookieMonster::SetCookieWithDetailsAsync(
922 const GURL& url, 932 const GURL& url,
923 const std::string& name, 933 const std::string& name,
924 const std::string& value, 934 const std::string& value,
925 const std::string& domain, 935 const std::string& domain,
926 const std::string& path, 936 const std::string& path,
927 const Time& expiration_time, 937 const Time& expiration_time,
928 bool secure, 938 bool secure,
929 bool http_only, 939 bool http_only,
930 bool first_party_only, 940 bool first_party_only,
941 bool enforce_prefixes,
931 CookiePriority priority, 942 CookiePriority priority,
932 const SetCookiesCallback& callback) { 943 const SetCookiesCallback& callback) {
933 scoped_refptr<SetCookieWithDetailsTask> task = new SetCookieWithDetailsTask( 944 scoped_refptr<SetCookieWithDetailsTask> task = new SetCookieWithDetailsTask(
934 this, url, name, value, domain, path, expiration_time, secure, http_only, 945 this, url, name, value, domain, path, expiration_time, secure, http_only,
935 first_party_only, priority, callback); 946 first_party_only, enforce_prefixes, priority, callback);
936 DoCookieTaskForURL(task, url); 947 DoCookieTaskForURL(task, url);
937 } 948 }
938 949
939 void CookieMonster::GetAllCookiesAsync(const GetCookieListCallback& callback) { 950 void CookieMonster::GetAllCookiesAsync(const GetCookieListCallback& callback) {
940 scoped_refptr<GetAllCookiesTask> task = new GetAllCookiesTask(this, callback); 951 scoped_refptr<GetAllCookiesTask> task = new GetAllCookiesTask(this, callback);
941 952
942 DoCookieTask(task); 953 DoCookieTask(task);
943 } 954 }
944 955
945 void CookieMonster::GetAllCookiesForURLWithOptionsAsync( 956 void CookieMonster::GetAllCookiesForURLWithOptionsAsync(
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 1116
1106 bool CookieMonster::SetCookieWithDetails(const GURL& url, 1117 bool CookieMonster::SetCookieWithDetails(const GURL& url,
1107 const std::string& name, 1118 const std::string& name,
1108 const std::string& value, 1119 const std::string& value,
1109 const std::string& domain, 1120 const std::string& domain,
1110 const std::string& path, 1121 const std::string& path,
1111 const base::Time& expiration_time, 1122 const base::Time& expiration_time,
1112 bool secure, 1123 bool secure,
1113 bool http_only, 1124 bool http_only,
1114 bool first_party_only, 1125 bool first_party_only,
1126 bool enforce_prefixes,
1115 CookiePriority priority) { 1127 CookiePriority priority) {
1116 base::AutoLock autolock(lock_); 1128 base::AutoLock autolock(lock_);
1117 1129
1118 if (!HasCookieableScheme(url)) 1130 if (!HasCookieableScheme(url))
1119 return false; 1131 return false;
1120 1132
1121 Time creation_time = CurrentTime(); 1133 Time creation_time = CurrentTime();
1122 last_time_seen_ = creation_time; 1134 last_time_seen_ = creation_time;
1123 1135
1124 scoped_ptr<CanonicalCookie> cc; 1136 scoped_ptr<CanonicalCookie> cc;
1125 cc.reset(CanonicalCookie::Create(url, name, value, domain, path, 1137 cc.reset(CanonicalCookie::Create(url, name, value, domain, path,
1126 creation_time, expiration_time, secure, 1138 creation_time, expiration_time, secure,
1127 http_only, first_party_only, priority)); 1139 http_only, first_party_only, priority));
1128 1140
1129 if (!cc.get()) 1141 if (!cc.get())
1130 return false; 1142 return false;
1131 1143
1132 CookieOptions options; 1144 CookieOptions options;
1133 options.set_include_httponly(); 1145 options.set_include_httponly();
1134 options.set_include_first_party_only(); 1146 options.set_include_first_party_only();
1147 if (enforce_prefixes)
1148 options.set_enforce_prefixes();
1135 return SetCanonicalCookie(&cc, creation_time, options); 1149 return SetCanonicalCookie(&cc, creation_time, options);
1136 } 1150 }
1137 1151
1138 bool CookieMonster::ImportCookies(const CookieList& list) { 1152 bool CookieMonster::ImportCookies(const CookieList& list) {
1139 base::AutoLock autolock(lock_); 1153 base::AutoLock autolock(lock_);
1140 MarkCookieStoreAsInitialized(); 1154 MarkCookieStoreAsInitialized();
1141 if (ShouldFetchAllCookiesWhenFetchingAnyCookie()) 1155 if (ShouldFetchAllCookiesWhenFetchingAnyCookie())
1142 FetchAllCookiesIfNecessary(); 1156 FetchAllCookiesIfNecessary();
1143 for (CookieList::const_iterator iter = list.begin(); iter != list.end(); 1157 for (CookieList::const_iterator iter = list.begin(); iter != list.end();
1144 ++iter) { 1158 ++iter) {
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 } 1895 }
1882 return SetCanonicalCookie(&cc, creation_time, options); 1896 return SetCanonicalCookie(&cc, creation_time, options);
1883 } 1897 }
1884 1898
1885 bool CookieMonster::SetCanonicalCookie(scoped_ptr<CanonicalCookie>* cc, 1899 bool CookieMonster::SetCanonicalCookie(scoped_ptr<CanonicalCookie>* cc,
1886 const Time& creation_time, 1900 const Time& creation_time,
1887 const CookieOptions& options) { 1901 const CookieOptions& options) {
1888 const std::string key(GetKey((*cc)->Domain())); 1902 const std::string key(GetKey((*cc)->Domain()));
1889 bool already_expired = (*cc)->IsExpired(creation_time); 1903 bool already_expired = (*cc)->IsExpired(creation_time);
1890 1904
1905 if (options.enforce_prefixes() && !CheckCookiePrefix(cc->get(), options)) {
1906 VLOG(kVlogSetCookies) << "SetCookie() not storing cookie '" << (*cc)->Name()
1907 << "' that violates prefix rules.";
1908 return false;
1909 }
1910
1891 if (DeleteAnyEquivalentCookie(key, **cc, options.exclude_httponly(), 1911 if (DeleteAnyEquivalentCookie(key, **cc, options.exclude_httponly(),
1892 already_expired)) { 1912 already_expired)) {
1893 VLOG(kVlogSetCookies) << "SetCookie() not clobbering httponly cookie"; 1913 VLOG(kVlogSetCookies) << "SetCookie() not clobbering httponly cookie";
1894 return false; 1914 return false;
1895 } 1915 }
1896 1916
1897 VLOG(kVlogSetCookies) << "SetCookie() key: " << key 1917 VLOG(kVlogSetCookies) << "SetCookie() key: " << key
1898 << " cc: " << (*cc)->DebugString(); 1918 << " cc: " << (*cc)->DebugString();
1899 1919
1900 // Realize that we might be setting an expired cookie, and the only point 1920 // Realize that we might be setting an expired cookie, and the only point
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
2355 it != hook_map_.end(); ++it) { 2375 it != hook_map_.end(); ++it) {
2356 std::pair<GURL, std::string> key = it->first; 2376 std::pair<GURL, std::string> key = it->first;
2357 if (cookie.IncludeForRequestURL(key.first, opts) && 2377 if (cookie.IncludeForRequestURL(key.first, opts) &&
2358 cookie.Name() == key.second) { 2378 cookie.Name() == key.second) {
2359 it->second->Notify(cookie, removed); 2379 it->second->Notify(cookie, removed);
2360 } 2380 }
2361 } 2381 }
2362 } 2382 }
2363 2383
2364 } // namespace net 2384 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/cookie_monster.h ('k') | net/cookies/cookie_monster_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698