Skip to content

Commit 78e84bc

Browse files
committed
http/cookie: Don't allow a partial domain-match against an IP
1 parent 6396592 commit 78e84bc

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

http/cookie.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ local function domain_match(domain_string, str)
9898
return str == domain_string or (
9999
str:sub(-#domain_string) == domain_string
100100
and str:sub(-#domain_string-1, -#domain_string-1) == "."
101-
-- TODO: check if IP address?
101+
and not http_util.is_ip(str)
102102
)
103103
end
104104

spec/cookie_spec.lua

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ describe("cookie module", function()
7878
local s = http_cookie.new_store()
7979
assert.falsy(s:store("example.com", "/", true, true, nil, http_cookie.parse_setcookie("foo=bar; Domain=subdomain.example.com")))
8080
end)
81+
it("doesn't domain-match a partial ip", function()
82+
local s = http_cookie.new_store()
83+
assert.falsy(s:store("127.0.0.1", "/", true, true, nil, http_cookie.parse_setcookie("foo=bar; Domain=0.0.1")))
84+
end)
8185
end)
8286
describe("domain-match on lookup", function()
8387
it("matches domains correctly when host_only flag is true", function()

0 commit comments

Comments
 (0)