From e1092aed3cc359f9961646ced748d0dd4fc1a539 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 15 Nov 2023 10:17:59 -0500 Subject: [PATCH] LibWeb: Don't reject worker scripts with a JavaScript MIME type The condition for checking if a script has a JS MIME type is currently flipped. Extract the check to a local to make it a bit easier to reason about at quick glance. --- Userland/Libraries/LibWeb/HTML/Scripting/Fetching.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Fetching.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/Fetching.cpp index 21933a6710..1abdc2db60 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/Fetching.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Fetching.cpp @@ -380,8 +380,12 @@ WebIDL::ExceptionOr fetch_classic_worker_script(AK::URL const& url, Enviro // - response's URL's scheme is an HTTP(S) scheme; and // - the result of extracting a MIME type from response's header list is not a JavaScript MIME type, auto maybe_mime_type = MUST(response->header_list()->extract_mime_type()); - if (response->url().has_value() && Fetch::Infrastructure::is_http_or_https_scheme(response->url()->scheme()) && (!maybe_mime_type.has_value() || maybe_mime_type->is_javascript())) { - dbgln("Invalid non-javascript mime type for worker script at {}", response->url().value()); + auto mime_type_is_javascript = maybe_mime_type.has_value() && maybe_mime_type->is_javascript(); + + if (response->url().has_value() && Fetch::Infrastructure::is_http_or_https_scheme(response->url()->scheme()) && !mime_type_is_javascript) { + auto mime_type_serialized = maybe_mime_type.has_value() ? MUST(maybe_mime_type->serialized()) : "unknown"_string; + dbgln("Invalid non-javascript mime type \"{}\" for worker script at {}", mime_type_serialized, response->url().value()); + // then run onComplete given null, and abort these steps. on_complete->function()(nullptr); return;