Truly independent web browser
LibHTTP: Treat an invalid Expires header as already expired
Andreas Kling4625db216816
diff --git a/Libraries/LibHTTP/Cache/Utilities.cpp b/Libraries/LibHTTP/Cache/Utilities.cppindex bc3d5f9f687..ab96e7ae872 100644--- a/Libraries/LibHTTP/Cache/Utilities.cpp+++ b/Libraries/LibHTTP/Cache/Utilities.cpp@@ -552,7 +552,14 @@ AK::Duration calculate_freshness_lifetime(u32 status_code, HeaderList const& hea// * If the Expires response header field (Section 5.3) is present, use its value minus the value of the Date response// header field (using the time the message was received if it is not present, as per Section 6.6.1 of [HTTP]), or- if (auto expires = parse_http_date(headers.get("Expires"sv)); expires.has_value()) {+ if (auto expires_header = headers.get("Expires"sv); expires_header.has_value()) {+ // https://httpwg.org/specs/rfc9111.html#field.expires+ // A cache recipient MUST interpret invalid date formats, especially the value "0", as representing a time in+ // the past (i.e., "already expired").+ auto expires = parse_http_date(*expires_header);+ if (!expires.has_value())+ return {};+auto date = parse_http_date(headers.get("Date"sv)).value_or_lazy_evaluated([&]() {return UnixDateTime::now() + current_time_offset_for_testing;});diff --git a/Tests/LibWeb/Text/expected/wpt-import/fetch/http-cache/freshness.any.sharedworker.txt b/Tests/LibWeb/Text/expected/wpt-import/fetch/http-cache/freshness.any.sharedworker.txtindex 340488ee522..a92d46f553c 100644--- a/Tests/LibWeb/Text/expected/wpt-import/fetch/http-cache/freshness.any.sharedworker.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/fetch/http-cache/freshness.any.sharedworker.txt@@ -2,14 +2,14 @@ Harness status: OKFound 17 tests-14 Pass-3 Fail+15 Pass+2 FailPass HTTP cache reuses a response with a future ExpiresPass HTTP cache does not reuse a response with a past ExpiresPass HTTP cache does not reuse a response with a present ExpiresPass HTTP cache does not reuse a response with an invalid ExpiresPass HTTP cache does not reuse a response with an invalid Expires with Last-Modified now-Fail HTTP cache does not reuse a response with an invalid Expires with past Last-Modified+Pass HTTP cache does not reuse a response with an invalid Expires with past Last-ModifiedPass HTTP cache reuses a response with positive Cache-Control: max-agePass HTTP cache does not reuse a response with Cache-Control: max-age=0Pass HTTP cache reuses a response with positive Cache-Control: max-age and a past Expiresdiff --git a/Tests/LibWeb/Text/expected/wpt-import/fetch/http-cache/freshness.any.txt b/Tests/LibWeb/Text/expected/wpt-import/fetch/http-cache/freshness.any.txtindex 340488ee522..a92d46f553c 100644--- a/Tests/LibWeb/Text/expected/wpt-import/fetch/http-cache/freshness.any.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/fetch/http-cache/freshness.any.txt@@ -2,14 +2,14 @@ Harness status: OKFound 17 tests-14 Pass-3 Fail+15 Pass+2 FailPass HTTP cache reuses a response with a future ExpiresPass HTTP cache does not reuse a response with a past ExpiresPass HTTP cache does not reuse a response with a present ExpiresPass HTTP cache does not reuse a response with an invalid ExpiresPass HTTP cache does not reuse a response with an invalid Expires with Last-Modified now-Fail HTTP cache does not reuse a response with an invalid Expires with past Last-Modified+Pass HTTP cache does not reuse a response with an invalid Expires with past Last-ModifiedPass HTTP cache reuses a response with positive Cache-Control: max-agePass HTTP cache does not reuse a response with Cache-Control: max-age=0Pass HTTP cache reuses a response with positive Cache-Control: max-age and a past Expiresdiff --git a/Tests/LibWeb/Text/expected/wpt-import/fetch/http-cache/freshness.any.worker.txt b/Tests/LibWeb/Text/expected/wpt-import/fetch/http-cache/freshness.any.worker.txtindex 340488ee522..a92d46f553c 100644--- a/Tests/LibWeb/Text/expected/wpt-import/fetch/http-cache/freshness.any.worker.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/fetch/http-cache/freshness.any.worker.txt@@ -2,14 +2,14 @@ Harness status: OKFound 17 tests-14 Pass-3 Fail+15 Pass+2 FailPass HTTP cache reuses a response with a future ExpiresPass HTTP cache does not reuse a response with a past ExpiresPass HTTP cache does not reuse a response with a present ExpiresPass HTTP cache does not reuse a response with an invalid ExpiresPass HTTP cache does not reuse a response with an invalid Expires with Last-Modified now-Fail HTTP cache does not reuse a response with an invalid Expires with past Last-Modified+Pass HTTP cache does not reuse a response with an invalid Expires with past Last-ModifiedPass HTTP cache reuses a response with positive Cache-Control: max-agePass HTTP cache does not reuse a response with Cache-Control: max-age=0Pass HTTP cache reuses a response with positive Cache-Control: max-age and a past Expires