From 2d60c5492627f6296542a8bf9a86d2a7aa04dc45 Mon Sep 17 00:00:00 2001 From: FranklinDM Date: Thu, 25 Jan 2024 13:48:31 +0800 Subject: [PATCH] Issue #2578 - Part 2: Implement preference for disabling CORS preflight requests if CORS is disabled --- netwerk/protocol/http/nsCORSListenerProxy.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/netwerk/protocol/http/nsCORSListenerProxy.cpp b/netwerk/protocol/http/nsCORSListenerProxy.cpp index a06a0df55e..8d4cd487ba 100644 --- a/netwerk/protocol/http/nsCORSListenerProxy.cpp +++ b/netwerk/protocol/http/nsCORSListenerProxy.cpp @@ -53,6 +53,7 @@ using namespace mozilla; static bool gDisableCORS = false; static bool gDisableCORSPrivateData = false; +static bool gBypassCORSPreflightRequest = false; static void LogBlockedRequest(nsIRequest* aRequest, @@ -414,6 +415,8 @@ nsCORSListenerProxy::Startup() "content.cors.disable"); Preferences::AddBoolVarCache(&gDisableCORSPrivateData, "content.cors.no_private_data"); + Preferences::AddBoolVarCache(&gBypassCORSPreflightRequest, + "content.cors.bypass_preflight_request"); } /* static */ @@ -543,6 +546,9 @@ nsCORSListenerProxy::CheckRequestApproved(nsIRequest* aRequest) } if (gDisableCORS) { + if (gBypassCORSPreflightRequest) { + return NS_OK; + } LogBlockedRequest(aRequest, "CORSDisabled", nullptr); return NS_ERROR_DOM_BAD_URI; } @@ -1413,6 +1419,10 @@ nsCORSListenerProxy::StartCORSPreflight(nsIChannel* aRequestChannel, *aPreflightChannel = nullptr; if (gDisableCORS) { + if (gBypassCORSPreflightRequest) { + aCallback->OnPreflightSucceeded(); + return NS_OK; + } LogBlockedRequest(aRequestChannel, "CORSDisabled", nullptr); return NS_ERROR_DOM_BAD_URI; }