Lightpanda: the headless browser designed for AI and automation
Merge pull request #4159 from lightpanda-io/cookie-ip-site
Karl Seguin6e2dc83119c9
diff --cc src/browser/webapi/storage/Cookie.zigindex 423cc9b91,bd6f443c3..e2f020ff3--- a/src/browser/webapi/storage/Cookie.zig+++ b/src/browser/webapi/storage/Cookie.zig@@@ -1080,17 -943,9 +1080,19 @@@ pub fn areHostsSameSite(target_host: []return std.mem.eql(u8, findSecondLevelDomain(target_host), findSecondLevelDomain(origin_host));}+// The site of a cookie domain or a host: its registrable domain, like+// Chrome's CookieMonster key. A cookie only applies to hosts with its key.+fn siteKey(domain: []const u8) []const u8 {+ const host = if (domain.len > 0 and domain[0] == '.') domain[1..] else domain;+ // findSecondLevelDomain keeps a single label as is, and Domain=localhost+ // is the one single-label domain parseDomain accepts.+ if (std.mem.endsWith(u8, host, ".localhost")) return "localhost";+ return findSecondLevelDomain(host);+}+fn findSecondLevelDomain(host: []const u8) []const u8 {+ // An IP address is its own site, not one per last two octets.+ if (isIpLiteral(host)) return host;var i = std.mem.findScalarLast(u8, host, '.') orelse return host;while (true) {i = std.mem.findScalarLast(u8, host[0..i], '.') orelse return host;