From 0cb9f4b66fd35e29fc22d115c45e0ff3de2cadfb Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 12 Nov 2025 12:06:53 -0500 Subject: [PATCH] LibWeb: Do not fetch empty CSS URLs If a CSS rule has a URL like `url("")`, it would resolve to the document URL itself. There isn't a context in which this would result in a valid resource, so the spec tells us to drop it. No test here because there isn't really a way to know when a CSS URL is fetched. We could use PerformanceResourceTiming, but that is only for HTTP(S) URLs. There is already an existing test for serialization of empty URLs, which still passes. --- Libraries/LibWeb/CSS/Fetch.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Libraries/LibWeb/CSS/Fetch.cpp b/Libraries/LibWeb/CSS/Fetch.cpp index 66d6ec2e67b..89d462b7348 100644 --- a/Libraries/LibWeb/CSS/Fetch.cpp +++ b/Libraries/LibWeb/CSS/Fetch.cpp @@ -40,6 +40,12 @@ static GC::Ptr fetch_a_style_resource_impl(Style [](::URL::URL const& url) { return url.to_string(); }, [](CSS::URL const& url) { return url.url(); }); + // https://drafts.csswg.org/css-values-4/#url-empty + // If the value of the is the empty string (like url("") or url()), the url must resolve to an invalid + // resource (similar to what the url about:invalid does). + if (url_string.is_empty()) + return {}; + auto parsed_url = DOMURL::parse(url_string, base); if (!parsed_url.has_value()) return {};