diff options
author | pauljensen@chromium.org <pauljensen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-13 19:27:48 +0000 |
---|---|---|
committer | pauljensen@chromium.org <pauljensen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-13 19:27:48 +0000 |
commit | bb3c4c5de24a6732e6f13f96935eea8cb1392c04 (patch) | |
tree | fb2b7ca0ed7ca8164b849c0824c01ff8e498c2cf /net/cookies/cookie_monster.cc | |
parent | 052f0983c534482292715f256fc99df4996ae6e7 (diff) | |
download | chromium_src-bb3c4c5de24a6732e6f13f96935eea8cb1392c04.zip chromium_src-bb3c4c5de24a6732e6f13f96935eea8cb1392c04.tar.gz chromium_src-bb3c4c5de24a6732e6f13f96935eea8cb1392c04.tar.bz2 |
Account for server vs host clock skew in cookie expiration times.
When setting a cookie's expiration time in the cookie store we need
to take into account any difference between the HTTP server and the
host machine's real time clock.
BUG=135131
TEST=net_unittests --gtest_filter=CookieMonster/CookieStoreTest/0.TestCookieDeletion
Review URL: https://chromiumcodereview.appspot.com/10692137
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146616 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/cookies/cookie_monster.cc')
-rw-r--r-- | net/cookies/cookie_monster.cc | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/net/cookies/cookie_monster.cc b/net/cookies/cookie_monster.cc index e44ba18..9851c9a 100644 --- a/net/cookies/cookie_monster.cc +++ b/net/cookies/cookie_monster.cc @@ -236,7 +236,9 @@ std::string CanonPath(const GURL& url, const ParsedCookie& pc) { return CanonPathWithString(url, path_string); } -Time CanonExpiration(const ParsedCookie& pc, const Time& current) { +Time CanonExpiration(const ParsedCookie& pc, + const Time& current, + const Time& server_time) { // First, try the Max-Age attribute. uint64 max_age = 0; if (pc.HasMaxAge() && @@ -250,8 +252,11 @@ Time CanonExpiration(const ParsedCookie& pc, const Time& current) { } // Try the Expires attribute. - if (pc.HasExpires()) - return CookieMonster::ParseCookieTime(pc.Expires()); + if (pc.HasExpires()) { + // Adjust for clock skew between server and host. + return current + (CookieMonster::ParseCookieTime(pc.Expires()) - + server_time); + } // Invalid or no expiration, persistent cookie. return Time(); @@ -1888,6 +1893,11 @@ bool CookieMonster::SetCookieWithCreationTimeAndOptions( creation_time = CurrentTime(); last_time_seen_ = creation_time; } + Time server_time; + if (options.has_server_time()) + server_time = options.server_time(); + else + server_time = creation_time; // Parse the cookie. ParsedCookie pc(cookie_line); @@ -1913,7 +1923,7 @@ bool CookieMonster::SetCookieWithCreationTimeAndOptions( pc.MACAlgorithm() : std::string(); scoped_ptr<CanonicalCookie> cc; - Time cookie_expires = CanonExpiration(pc, creation_time); + Time cookie_expires = CanonExpiration(pc, creation_time, server_time); cc.reset(new CanonicalCookie(url, pc.Name(), pc.Value(), cookie_domain, cookie_path, mac_key, mac_algorithm, @@ -2375,7 +2385,7 @@ CookieMonster::CanonicalCookie::CanonicalCookie(const GURL& url, secure_(pc.IsSecure()), httponly_(pc.IsHttpOnly()) { if (pc.HasExpires()) - expiry_date_ = CanonExpiration(pc, creation_date_); + expiry_date_ = CanonExpiration(pc, creation_date_, creation_date_); else SetSessionCookieExpiryTime(); |