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

Unified Diff: net/cookies/cookie_monster.cc

Issue 2861063003: Remove dangerous CanonicalCookie::Create method. (Closed)
Patch Set: Use creation_time for last_access_time as per Elly's suggestion. Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/cookies/canonical_cookie_unittest.cc ('k') | net/cookies/cookie_monster_store_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cookies/cookie_monster.cc
diff --git a/net/cookies/cookie_monster.cc b/net/cookies/cookie_monster.cc
index 2272d7b08ab49ca58e9ce4024cd2ebb369efdc07..146e8acdd1a96b725398e12f2ed8e0b9264c34b8 100644
--- a/net/cookies/cookie_monster.cc
+++ b/net/cookies/cookie_monster.cc
@@ -1058,16 +1058,43 @@ bool CookieMonster::SetCookieWithDetails(const GURL& url,
last_time_seen_ = actual_creation_time;
}
+ // Validate consistency of passed arguments.
+ if (ParsedCookie::ParseTokenString(name) != name ||
+ ParsedCookie::ParseValueString(value) != value ||
+ ParsedCookie::ParseValueString(domain) != domain ||
+ ParsedCookie::ParseValueString(path) != path) {
+ return false;
+ }
+
+ // Validate passed arguments against URL.
+ if (secure && !url.SchemeIsCryptographic())
+ return false;
+
+ std::string cookie_domain;
+ if (!cookie_util::GetCookieDomainWithString(url, domain, &cookie_domain))
+ return false;
+
+ std::string cookie_path = CanonicalCookie::CanonPathWithString(url, path);
+ if (!path.empty() && cookie_path != path)
+ return false;
+
+ // Canonicalize path again to make sure it escapes characters as needed.
+ url::Component path_component(0, cookie_path.length());
+ url::RawCanonOutputT<char> canon_path;
+ url::Component canon_path_component;
+ url::CanonicalizePath(cookie_path.data(), path_component, &canon_path,
+ &canon_path_component);
+ cookie_path = std::string(canon_path.data() + canon_path_component.begin,
+ canon_path_component.len);
+
std::unique_ptr<CanonicalCookie> cc(CanonicalCookie::Create(
- url, name, value, domain, path, actual_creation_time, expiration_time,
- secure, http_only, same_site, priority));
+ name, value, cookie_domain, cookie_path, actual_creation_time,
+ expiration_time, last_access_time, secure, http_only, same_site,
+ priority));
if (!cc.get())
return false;
- if (!last_access_time.is_null())
- cc->SetLastAccessDate(last_access_time);
-
CookieOptions options;
options.set_include_httponly();
options.set_same_site_cookie_mode(
« no previous file with comments | « net/cookies/canonical_cookie_unittest.cc ('k') | net/cookies/cookie_monster_store_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698