0

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:
deanm@chromium.org
2009-01-23 10:50:51 +00:00
parent 79d59e7a51
commit c3a756b6e1
2 changed files with 12 additions and 2 deletions

@ -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));
}
}