Skip to content

Commit c6f23ee

Browse files
committed
cookies: accept localhost domain
1 parent e9920ca commit c6f23ee

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/browser/storage/cookie.zig

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ pub const Cookie = struct {
358358
value = value[1..];
359359
}
360360

361-
if (std.mem.indexOfScalarPos(u8, value, 0, '.') == null) {
361+
if (std.mem.indexOfScalarPos(u8, value, 0, '.') == null and std.mem.eql(u8, "localhost", value) == false) {
362362
// can't set a cookie for a TLD
363363
return error.InvalidDomain;
364364
}
@@ -839,6 +839,17 @@ test "Cookie: parse all" {
839839
.domain = ".lightpanda.io",
840840
.expires = std.time.timestamp() + 30,
841841
}, "https://lightpanda.io/cms/users", "user-id=9000; HttpOnly; Max-Age=30; Secure; path=/; Domain=lightpanda.io");
842+
843+
try expectCookie(.{
844+
.name = "app_session",
845+
.value = "123",
846+
.path = "/",
847+
.http_only = true,
848+
.secure = false,
849+
.domain = ".localhost",
850+
.same_site = .lax,
851+
.expires = std.time.timestamp() + 7200,
852+
}, "http://localhost:8000/login", "app_session=123; Max-Age=7200; path=/; domain=localhost; httponly; samesite=lax");
842853
}
843854

844855
test "Cookie: parse domain" {
@@ -849,6 +860,8 @@ test "Cookie: parse domain" {
849860
try expectAttribute(.{ .domain = ".dev.lightpanda.io" }, "http://dev.lightpanda.io/", "b;domain=dev.lightpanda.io");
850861
try expectAttribute(.{ .domain = ".lightpanda.io" }, "http://dev.lightpanda.io/", "b;domain=lightpanda.io");
851862
try expectAttribute(.{ .domain = ".lightpanda.io" }, "http://dev.lightpanda.io/", "b;domain=.lightpanda.io");
863+
try expectAttribute(.{ .domain = ".localhost" }, "http://localhost/", "b;domain=localhost");
864+
try expectAttribute(.{ .domain = ".localhost" }, "http://localhost/", "b;domain=.localhost");
852865

853866
try expectError(error.InvalidDomain, "http://lightpanda.io/", "b;domain=io");
854867
try expectError(error.InvalidDomain, "http://lightpanda.io/", "b;domain=.io");

0 commit comments

Comments
 (0)