Skip to content

Commit 73266c8

Browse files
IdanHotrflynn89
authored andcommitted
LibWeb: Add missing cookie-age-limit steps to CookieStore::set()
1 parent e059c9d commit 73266c8

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

Libraries/LibWeb/Cookie/ParsedCookie.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,6 @@ void process_attribute(URL::URL const& url, ParsedCookie& parsed_cookie, StringV
184184
}
185185
}
186186

187-
static constexpr AK::Duration maximum_cookie_age()
188-
{
189-
return AK::Duration::from_seconds(400LL * 24 * 60 * 60);
190-
}
191-
192187
// https://www.ietf.org/archive/id/draft-ietf-httpbis-rfc6265bis-15.html#section-5.6.1
193188
void on_expires_attribute(ParsedCookie& parsed_cookie, StringView attribute_value)
194189
{
@@ -201,7 +196,7 @@ void on_expires_attribute(ParsedCookie& parsed_cookie, StringView attribute_valu
201196

202197
// 3. Let cookie-age-limit be the maximum age of the cookie (which SHOULD be 400 days in the future or sooner, see
203198
// Section 5.5).
204-
auto cookie_age_limit = UnixDateTime::now() + maximum_cookie_age();
199+
auto cookie_age_limit = UnixDateTime::now() + maximum_cookie_age;
205200

206201
// 4. If the expiry-time is more than cookie-age-limit, the user agent MUST set the expiry time to cookie-age-limit
207202
// in seconds.
@@ -243,7 +238,7 @@ void on_max_age_attribute(ParsedCookie& parsed_cookie, StringView attribute_valu
243238
}
244239

245240
// 5. Let cookie-age-limit be the maximum age of the cookie (which SHOULD be 400 days or less, see Section 5.5).
246-
auto cookie_age_limit = maximum_cookie_age();
241+
auto cookie_age_limit = maximum_cookie_age;
247242

248243
// 6. Set delta-seconds to the smaller of its present value and cookie-age-limit.
249244
if (*delta_seconds > cookie_age_limit.to_seconds())

Libraries/LibWeb/Cookie/ParsedCookie.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ WEB_API bool cookie_contains_invalid_control_character(StringView);
3333
WEB_API bool domain_matches(StringView string, StringView domain_string);
3434
WEB_API String default_path(URL::URL const&);
3535

36+
constexpr inline AK::Duration maximum_cookie_age = AK::Duration::from_seconds(400LL * 24 * 60 * 60);
37+
3638
}
3739

3840
namespace IPC {

Libraries/LibWeb/CookieStore/CookieStore.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,21 @@ static bool set_a_cookie(PageClient& client, URL::URL const& url, String name, S
455455
}
456456

457457
// 13. If expires is given, then append `Expires`/expires (date serialized) to attributes.
458-
if (expires.has_value())
459-
parsed_cookie.expiry_time_from_expires_attribute = UnixDateTime::from_milliseconds_since_epoch(expires.value());
458+
if (expires.has_value()) {
459+
auto expiry_time = UnixDateTime::from_milliseconds_since_epoch(expires.value());
460+
461+
// https://www.ietf.org/archive/id/draft-ietf-httpbis-rfc6265bis-15.html#section-5.6.1
462+
// 3. Let cookie-age-limit be the maximum age of the cookie (which SHOULD be 400 days in the future or sooner, see
463+
// Section 5.5).
464+
auto cookie_age_limit = UnixDateTime::now() + Cookie::maximum_cookie_age;
465+
466+
// 4. If the expiry-time is more than cookie-age-limit, the user agent MUST set the expiry time to cookie-age-limit
467+
// in seconds.
468+
if (expiry_time.seconds_since_epoch() > cookie_age_limit.seconds_since_epoch())
469+
expiry_time = cookie_age_limit;
470+
471+
parsed_cookie.expiry_time_from_expires_attribute = expiry_time;
472+
}
460473

461474
// 14. If path is the empty string, then set path to the serialized cookie default path of url.
462475
if (path.is_empty())

0 commit comments

Comments
 (0)