From 1f3285eb0410ff5c902e148932205d9e4b7fbd9b Mon Sep 17 00:00:00 2001 From: circl Date: Mon, 10 Jun 2024 18:06:37 +0200 Subject: [PATCH] LibWeb: Restrict fetching file: and resource: URLs to internal pages They are now blocked on pages which: - Don't have an opaque origin (should be only user-initiated or about:) - Aren't other file: pages - Aren't other resource: pages --- .../Libraries/LibWeb/Fetch/Fetching/Fetching.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp index fade773d5305..2a1a2ec3cde8 100644 --- a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp @@ -871,20 +871,20 @@ WebIDL::ExceptionOr> scheme_fetch(JS::Realm& r return PendingResponse::create(vm, request, response); } // -> "file" - else if (request->current_url().scheme() == "file"sv) { + // AD-HOC: "resource" + else if (request->current_url().scheme() == "file"sv || request->current_url().scheme() == "resource"sv) { // For now, unfortunate as it is, file: URLs are left as an exercise for the reader. // When in doubt, return a network error. - return TRY(nonstandard_resource_loader_file_or_http_network_fetch(realm, fetch_params)); + if (request->origin().has() && (request->origin().get().is_opaque() || request->origin().get().scheme() == "file"sv || request->origin().get().scheme() == "resource"sv)) + return TRY(nonstandard_resource_loader_file_or_http_network_fetch(realm, fetch_params)); + else + return PendingResponse::create(vm, request, Infrastructure::Response::network_error(vm, "Request with 'file:' or 'resource:' URL blocked"sv)); } // -> HTTP(S) scheme else if (Infrastructure::is_http_or_https_scheme(request->current_url().scheme())) { // Return the result of running HTTP fetch given fetchParams. return http_fetch(realm, fetch_params); } - // AD-HOC: "resource" - else if (request->current_url().scheme() == "resource"sv) { - return TRY(nonstandard_resource_loader_file_or_http_network_fetch(realm, fetch_params)); - } // 4. Return a network error. auto message = request->current_url().scheme() == "about"sv