summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-23 10:50:51 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-23 10:50:51 +0000
commitc3a756b6e1a2a7160237d26c515e155d386acde8 (patch)
tree3fe30fe6076bbbc00652b0345f4055f50295328d /net
parent79d59e7a514e31f17c65309b403f4cd6ebfecff5 (diff)
downloadchromium_src-c3a756b6e1a2a7160237d26c515e155d386acde8.zip
chromium_src-c3a756b6e1a2a7160237d26c515e155d386acde8.tar.gz
chromium_src-c3a756b6e1a2a7160237d26c515e155d386acde8.tar.bz2
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
Diffstat (limited to 'net')
-rw-r--r--net/base/cookie_monster.cc8
-rw-r--r--net/base/cookie_monster_unittest.cc6
2 files changed, 12 insertions, 2 deletions
diff --git a/net/base/cookie_monster.cc b/net/base/cookie_monster.cc
index 6d9afcb..288ea0f 100644
--- a/net/base/cookie_monster.cc
+++ b/net/base/cookie_monster.cc
@@ -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;
diff --git a/net/base/cookie_monster_unittest.cc b/net/base/cookie_monster_unittest.cc
index 1d5d963..48843d1 100644
--- a/net/base/cookie_monster_unittest.cc
+++ b/net/base/cookie_monster_unittest.cc
@@ -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));
}
}