mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:47:35 +00:00
Browser: Process Domain cookie attribute
This commit is contained in:
parent
a554676008
commit
3d53af354e
2 changed files with 24 additions and 4 deletions
|
@ -56,7 +56,7 @@ void CookieJar::set_cookie(const URL& url, const String& cookie_string)
|
||||||
if (!domain.has_value())
|
if (!domain.has_value())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto new_cookie = parse_cookie(cookie_string);
|
auto new_cookie = parse_cookie(cookie_string, *domain);
|
||||||
if (!new_cookie.has_value())
|
if (!new_cookie.has_value())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ Optional<String> CookieJar::canonicalize_domain(const URL& url)
|
||||||
return url.host().to_lowercase();
|
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
|
// https://tools.ietf.org/html/rfc6265#section-5.2
|
||||||
StringView name_value_pair;
|
StringView name_value_pair;
|
||||||
|
@ -131,6 +131,7 @@ Optional<Cookie> CookieJar::parse_cookie(const String& cookie_string)
|
||||||
Cookie cookie { name, value };
|
Cookie cookie { name, value };
|
||||||
|
|
||||||
cookie.expiry_time = Core::DateTime::create(AK::NumericLimits<unsigned>::max());
|
cookie.expiry_time = Core::DateTime::create(AK::NumericLimits<unsigned>::max());
|
||||||
|
cookie.domain = move(default_domain);
|
||||||
|
|
||||||
parse_attributes(cookie, unparsed_attributes);
|
parse_attributes(cookie, unparsed_attributes);
|
||||||
return cookie;
|
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
|
// 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)
|
void CookieJar::on_path_attribute([[maybe_unused]] Cookie& cookie, [[maybe_unused]] StringView attribute_value)
|
||||||
|
|
|
@ -38,6 +38,7 @@ struct Cookie {
|
||||||
String name;
|
String name;
|
||||||
String value;
|
String value;
|
||||||
Core::DateTime expiry_time {};
|
Core::DateTime expiry_time {};
|
||||||
|
String domain {};
|
||||||
};
|
};
|
||||||
|
|
||||||
class CookieJar {
|
class CookieJar {
|
||||||
|
@ -47,7 +48,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Optional<String> canonicalize_domain(const URL& url);
|
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 parse_attributes(Cookie& cookie, StringView unparsed_attributes);
|
||||||
static void process_attribute(Cookie& cookie, StringView attribute_name, StringView attribute_value);
|
static void process_attribute(Cookie& cookie, StringView attribute_name, StringView attribute_value);
|
||||||
static void on_expires_attribute(Cookie& cookie, StringView attribute_value);
|
static void on_expires_attribute(Cookie& cookie, StringView attribute_value);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue