Truly independent web browser
LibWeb: Skip the CORP check for network errors in HTTP fetch
Andreas Kling1960a1695353
diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cppindex 8534156a56c..ef49444f383 100644--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp@@ -1885,7 +1885,10 @@ GC::Ref<PendingResponse> http_fetch(JS::Realm& realm, Infrastructure::FetchParam// worker can have different embedder policies.// NB: request's policy container is a copy of its client's, or a new one when it has no client.auto const& client_embedder_policy = request->policy_container().get<NonnullRefPtr<HTML::PolicyContainer const>>()->embedder_policy;- if ((request->response_tainting() == Infrastructure::Request::ResponseTainting::Opaque || response->type() == Infrastructure::Response::Type::Opaque)+ // AD-HOC: Skip the check for network errors. They have no URL for the check to compare origins with, and+ // blocking one would only replace it with another network error.+ if (!internal_response->is_network_error()+ && (request->response_tainting() == Infrastructure::Request::ResponseTainting::Opaque || response->type() == Infrastructure::Response::Type::Opaque)&& cross_origin_resource_policy_check(request->origin().get<URL::Origin>(), client_embedder_policy, *internal_response) == Infrastructure::RequestOrResponseBlocking::Blocked) {stop_discarded_response_body(*controller, *internal_response);returned_pending_response->resolve(Infrastructure::Response::network_error("Response was blocked by cross-origin resource policy check"_string));diff --git a/Tests/LibWeb/Text/expected/Fetch/fetch-keepalive-over-quota-with-require-corp.txt b/Tests/LibWeb/Text/expected/Fetch/fetch-keepalive-over-quota-with-require-corp.txtnew file mode 100644index 00000000000..45785bbd81d--- /dev/null+++ b/Tests/LibWeb/Text/expected/Fetch/fetch-keepalive-over-quota-with-require-corp.txt@@ -0,0 +1 @@+rejected: TypeErrordiff --git a/Tests/LibWeb/Text/input/Fetch/fetch-keepalive-over-quota-with-require-corp.html b/Tests/LibWeb/Text/input/Fetch/fetch-keepalive-over-quota-with-require-corp.htmlnew file mode 100644index 00000000000..9ebc526675b--- /dev/null+++ b/Tests/LibWeb/Text/input/Fetch/fetch-keepalive-over-quota-with-require-corp.html@@ -0,0 +1,21 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ promiseTest(async () => {+ const server = httpTestServer();+ const url = new URL(await server.createEcho("POST", "/fetch-keepalive-over-quota-with-require-corp", {+ status: 200,+ headers: { "Content-Type": "text/plain" },+ body: "",+ }));+ url.hostname = uniqueLocalhostHostname("keepalive-over-quota");++ // A keepalive body over 64 KiB makes fetch return an early network error, which has no URL.+ try {+ await fetch(url, { method: "POST", mode: "no-cors", keepalive: true, body: "*".repeat(65537) });+ println("sent");+ } catch (error) {+ println(`rejected: ${error.name}`);+ }+ });+</script>diff --git a/Tests/LibWeb/Text/input/Fetch/fetch-keepalive-over-quota-with-require-corp.html.headers b/Tests/LibWeb/Text/input/Fetch/fetch-keepalive-over-quota-with-require-corp.html.headersnew file mode 100644index 00000000000..6604450991a--- /dev/null+++ b/Tests/LibWeb/Text/input/Fetch/fetch-keepalive-over-quota-with-require-corp.html.headers@@ -0,0 +1 @@+Cross-Origin-Embedder-Policy: require-corp