Support domain=IPADDR if it matches the url ip address exactly.
This doesn't do anything special to handle ipv6, dotless ip address, etc. BUG=3699 Review URL: http://codereview.chromium.org/18657 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8551 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
@ -259,8 +259,12 @@ static bool GetCookieDomainKey(const GURL& url,
|
||||
const CookieMonster::ParsedCookie& pc,
|
||||
std::string* cookie_domain_key) {
|
||||
const std::string url_host(url.host());
|
||||
if (!pc.HasDomain() || pc.Domain().empty()) {
|
||||
// No domain was specified in cookie -- default to host cookie.
|
||||
|
||||
// If no domain was specified in the cookie, default to a host cookie.
|
||||
// We match IE/Firefox in allowing a domain=IPADDR if it matches the url
|
||||
// ip address hostname exactly. It should be treated as a host cookie.
|
||||
if (!pc.HasDomain() || pc.Domain().empty() ||
|
||||
(url.HostIsIPAddress() && url_host == pc.Domain())) {
|
||||
*cookie_domain_key = url_host;
|
||||
DCHECK((*cookie_domain_key)[0] != '.');
|
||||
return true;
|
||||
|
@ -406,6 +406,12 @@ TEST(CookieMonsterTest, TestIpAddress) {
|
||||
EXPECT_FALSE(cm.SetCookie(url_ip, "b=2; domain=.1.2.3.4"));
|
||||
EXPECT_FALSE(cm.SetCookie(url_ip, "c=3; domain=.3.4"));
|
||||
EXPECT_EQ("", cm.GetCookies(url_ip));
|
||||
// It should be allowed to set a cookie if domain= matches the IP address
|
||||
// exactly. This matches IE/Firefox, even though it seems a bit wrong.
|
||||
EXPECT_FALSE(cm.SetCookie(url_ip, "b=2; domain=1.2.3.3"));
|
||||
EXPECT_EQ("", cm.GetCookies(url_ip));
|
||||
EXPECT_TRUE(cm.SetCookie(url_ip, "b=2; domain=1.2.3.4"));
|
||||
EXPECT_EQ("b=2", cm.GetCookies(url_ip));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user