summaryrefslogtreecommitdiff
path: root/Userland/Applications
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-04-11 23:47:43 -0400
committerAndreas Kling <kling@serenityos.org>2021-04-12 08:57:44 +0200
commit3d53af354eb3c5a112b8ba82d54582e29d713e77 (patch)
tree5b8ad6eea37829e62d0e31b6fbcd768c1101ae55 /Userland/Applications
parenta5546760086267fe6bc6f29ce6f03a3b1b15f3d7 (diff)
downloadserenity-3d53af354eb3c5a112b8ba82d54582e29d713e77.zip
Browser: Process Domain cookie attribute
Diffstat (limited to 'Userland/Applications')
-rw-r--r--Userland/Applications/Browser/CookieJar.cpp25
-rw-r--r--Userland/Applications/Browser/CookieJar.h3
2 files changed, 24 insertions, 4 deletions
diff --git a/Userland/Applications/Browser/CookieJar.cpp b/Userland/Applications/Browser/CookieJar.cpp
index fdc4edd3c1..1e1593f617 100644
--- a/Userland/Applications/Browser/CookieJar.cpp
+++ b/Userland/Applications/Browser/CookieJar.cpp
@@ -56,7 +56,7 @@ void CookieJar::set_cookie(const URL& url, const String& cookie_string)
if (!domain.has_value())
return;
- auto new_cookie = parse_cookie(cookie_string);
+ auto new_cookie = parse_cookie(cookie_string, *domain);
if (!new_cookie.has_value())
return;
@@ -86,7 +86,7 @@ Optional<String> CookieJar::canonicalize_domain(const URL& url)
return url.host().to_lowercase();
}
-Optional<Cookie> CookieJar::parse_cookie(const String& cookie_string)
+Optional<Cookie> CookieJar::parse_cookie(const String& cookie_string, String default_domain)
{
// https://tools.ietf.org/html/rfc6265#section-5.2
StringView name_value_pair;
@@ -131,6 +131,7 @@ Optional<Cookie> CookieJar::parse_cookie(const String& cookie_string)
Cookie cookie { name, value };
cookie.expiry_time = Core::DateTime::create(AK::NumericLimits<unsigned>::max());
+ cookie.domain = move(default_domain);
parse_attributes(cookie, unparsed_attributes);
return cookie;
@@ -231,9 +232,27 @@ void CookieJar::on_max_age_attribute(Cookie& cookie, StringView attribute_value)
}
}
-void CookieJar::on_domain_attribute([[maybe_unused]] Cookie& cookie, [[maybe_unused]] StringView attribute_value)
+void CookieJar::on_domain_attribute(Cookie& cookie, StringView attribute_value)
{
// https://tools.ietf.org/html/rfc6265#section-5.2.3
+
+ // If the attribute-value is empty, the behavior is undefined. However, the user agent SHOULD ignore the cookie-av entirely.
+ if (attribute_value.is_empty())
+ return;
+
+ StringView cookie_domain;
+
+ // If the first character of the attribute-value string is %x2E ("."):
+ if (attribute_value[0] == '.') {
+ // Let cookie-domain be the attribute-value without the leading %x2E (".") character.
+ cookie_domain = attribute_value.substring_view(1);
+ } else {
+ // Let cookie-domain be the entire attribute-value.
+ cookie_domain = attribute_value;
+ }
+
+ // Convert the cookie-domain to lower case.
+ cookie.domain = String(cookie_domain).to_lowercase();
}
void CookieJar::on_path_attribute([[maybe_unused]] Cookie& cookie, [[maybe_unused]] StringView attribute_value)
diff --git a/Userland/Applications/Browser/CookieJar.h b/Userland/Applications/Browser/CookieJar.h
index 8655307cf8..f7443b5f1c 100644
--- a/Userland/Applications/Browser/CookieJar.h
+++ b/Userland/Applications/Browser/CookieJar.h
@@ -38,6 +38,7 @@ struct Cookie {
String name;
String value;
Core::DateTime expiry_time {};
+ String domain {};
};
class CookieJar {
@@ -47,7 +48,7 @@ public:
private:
static Optional<String> canonicalize_domain(const URL& url);
- static Optional<Cookie> parse_cookie(const String& cookie_string);
+ static Optional<Cookie> parse_cookie(const String& cookie_string, String default_domain);
static void parse_attributes(Cookie& cookie, StringView unparsed_attributes);
static void process_attribute(Cookie& cookie, StringView attribute_name, StringView attribute_value);
static void on_expires_attribute(Cookie& cookie, StringView attribute_value);