1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:47:35 +00:00

Browser+LibWeb+WebContent: Store cookie expiry times in UTC

We are currently converting parsed expiry times to local time, whereas
the RFC dictates we parse them as UTC. When expiring cookies, we must
also use the current UTC time to compare against the cookies' expiry
times.
This commit is contained in:
Timothy Flynn 2023-02-24 11:51:56 -05:00 committed by Tim Flynn
parent 1858163d3c
commit 87c4080d00
8 changed files with 83 additions and 47 deletions

View file

@ -1,15 +1,38 @@
/*
* Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "Cookie.h"
#include <LibCore/DateTime.h>
#include <LibIPC/Decoder.h>
#include <LibIPC/Encoder.h>
namespace Web::Cookie {
static DeprecatedString time_to_string(Time const& time)
{
auto local_time = Core::DateTime::from_timestamp(time.to_seconds());
return local_time.to_deprecated_string("%Y-%m-%d %H:%M:%S %Z"sv);
}
DeprecatedString Cookie::creation_time_to_string() const
{
return time_to_string(creation_time);
}
DeprecatedString Cookie::last_access_time_to_string() const
{
return time_to_string(last_access_time);
}
DeprecatedString Cookie::expiry_time_to_string() const
{
return time_to_string(expiry_time);
}
StringView same_site_to_string(SameSite same_site)
{
switch (same_site) {
@ -64,11 +87,11 @@ ErrorOr<Web::Cookie::Cookie> IPC::decode(Decoder& decoder)
auto value = TRY(decoder.decode<DeprecatedString>());
auto domain = TRY(decoder.decode<DeprecatedString>());
auto path = TRY(decoder.decode<DeprecatedString>());
auto creation_time = TRY(decoder.decode<Core::DateTime>());
auto expiry_time = TRY(decoder.decode<Core::DateTime>());
auto creation_time = TRY(decoder.decode<Time>());
auto expiry_time = TRY(decoder.decode<Time>());
auto host_only = TRY(decoder.decode<bool>());
auto http_only = TRY(decoder.decode<bool>());
auto last_access_time = TRY(decoder.decode<Core::DateTime>());
auto last_access_time = TRY(decoder.decode<Time>());
auto persistent = TRY(decoder.decode<bool>());
auto secure = TRY(decoder.decode<bool>());
auto same_site = TRY(decoder.decode<Web::Cookie::SameSite>());