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.
This commit is contained in:
Timothy Flynn 2023-11-15 10:17:59 -05:00 committed by Tim Flynn
parent 50406f541b
commit e1092aed3c
Notes: sideshowbarker 2024-07-17 05:03:11 +09:00

View file

@ -380,8 +380,12 @@ WebIDL::ExceptionOr<void> 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;