]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Block all preload requests. https://redmine.stoutner.com/issues/1195
authorSoren Stoutner <soren@stoutner.com>
Thu, 26 Jun 2025 18:27:28 +0000 (11:27 -0700)
committerSoren Stoutner <soren@stoutner.com>
Thu, 26 Jun 2025 18:27:28 +0000 (11:27 -0700)
src/helpers/FilterListHelper.cpp
src/helpers/FilterListHelper.h
src/interceptors/UrlRequestInterceptor.cpp

index 9d8d2e25831a77d3f2b1eca72b52325ead26a48f..0f81e0df2961d1503cc1bfbdba4ac115824e9da7 100644 (file)
@@ -76,6 +76,7 @@ FilterListHelper::FilterListHelper()
     RESOURCE_TYPE_NAVIGATION_PRELOAD_SUB_FRAME = i18nc("Resource type preload sub frame", "Preload Sub Frame");
     RESOURCE_TYPE_WEB_SOCKET = i18nc("Resource type web socket", "Web Socket");
     RESOURCE_TYPE_UNKNOWN = i18nc("Resource type unknown", "Unknown");
+    RESOURCE_TYPE_JSON = i18nc("Resource type JSON", "JSON");
 
     // Populate the translated sublist strings.  Translated entries cannot be public static const.
     MAIN_ALLOWLIST_STRING = i18nc("Main allowlist", "Main Allow List");
@@ -808,6 +809,7 @@ QString FilterListHelper::getResourceTypeString(int resourceTypeInt) const
         case QWebEngineUrlRequestInfo::ResourceTypeNavigationPreloadMainFrame: return RESOURCE_TYPE_NAVIGATION_PRELOAD_MAIN_FRAME;
         case QWebEngineUrlRequestInfo::ResourceTypeNavigationPreloadSubFrame: return RESOURCE_TYPE_NAVIGATION_PRELOAD_SUB_FRAME;
         case QWebEngineUrlRequestInfo::ResourceTypeWebSocket: return RESOURCE_TYPE_WEB_SOCKET;
+        case QWebEngineUrlRequestInfo::ResourceTypeJson: return RESOURCE_TYPE_JSON;
         default: return RESOURCE_TYPE_UNKNOWN;
     }
 }
index 7241dea362dc49b93575070e1496e4507579ccd5..4115ae173d3a3c129ed2c7f2342bae15381f3f99 100644 (file)
@@ -106,6 +106,7 @@ private:
     QString RESOURCE_TYPE_NAVIGATION_PRELOAD_SUB_FRAME;
     QString RESOURCE_TYPE_WEB_SOCKET;
     QString RESOURCE_TYPE_UNKNOWN;
+    QString RESOURCE_TYPE_JSON;
 
     // The private translated sublist strings.
     QString MAIN_ALLOWLIST_STRING;
index ccaa179b6f8e152a3512b572564751806475fe74..e7b7807f4aa30bde06b8cc45ec52f7f3d382135c 100644 (file)
@@ -46,8 +46,40 @@ void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &urlReques
     requestStructPointer->urlString = urlRequestInfo.requestUrl().toString();
     requestStructPointer->webPageUrlString = urlRequestInfo.firstPartyUrl().toString();
 
-    // Check the filter lists.
-    bool continueProcessing = globalFilterListHelperPointer->checkFilterLists(privacyWebEngineViewPointer, urlRequestInfo, requestStructPointer);
+    // Create a continue processing flag.
+    bool continueProcessing = true;
+
+    // Block certain resource types.
+    switch (urlRequestInfo.resourceType())
+    {
+        case QWebEngineUrlRequestInfo::ResourceTypeNavigationPreloadMainFrame:
+        case QWebEngineUrlRequestInfo::ResourceTypeNavigationPreloadSubFrame:
+        {
+            // Block the request.
+            urlRequestInfo.block(true);
+
+            // Mark the request struct as blocked.
+            requestStructPointer->dispositionInt = FilterListHelper::BLOCKED;
+
+            // Mark the preload request as blocked by the default behavior.
+            requestStructPointer->filterListTitle = i18nc("Default preload blocking", "Default blocking of all preload requests.");
+
+            // Set the continue processing flag.
+            continueProcessing = false;
+
+            break;
+        }
+
+        default:
+        {
+            // Do nothing.
+            break;
+        }
+    }
+
+    // Check the filter lists if it hasn't already been handled.
+    if (continueProcessing)
+        continueProcessing = globalFilterListHelperPointer->checkFilterLists(privacyWebEngineViewPointer, urlRequestInfo, requestStructPointer);
 
     // Further process the request if it hasn't already been handled.
     if (continueProcessing) {
@@ -66,6 +98,9 @@ void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &urlReques
                 // Mark the ping as blocked by the default behavior.
                 requestStructPointer->filterListTitle = i18nc("Default HTTP ping blocking", "Default blocking of all HTTP ping requests.");
 
+                // Set the continue processing flag.
+                continueProcessing = false;
+
                 // Display the HTTP Ping blocked dialog.
                 Q_EMIT displayHttpPingDialog(urlRequestInfo.requestUrl().toString());
 
@@ -80,57 +115,62 @@ void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &urlReques
         }
     }
 
-    // Handle the request according to the navigation type.
-    switch (urlRequestInfo.navigationType())
+    // Handle the request according to the navigation type if it hasn't already been handled.
+    if (continueProcessing)
     {
-        case QWebEngineUrlRequestInfo::NavigationTypeLink:
-        case QWebEngineUrlRequestInfo::NavigationTypeTyped:
-        case QWebEngineUrlRequestInfo::NavigationTypeFormSubmitted:
-        case QWebEngineUrlRequestInfo::NavigationTypeRedirect:
-        case QWebEngineUrlRequestInfo::NavigationTypeOther:
+        switch (urlRequestInfo.navigationType())
         {
-            // Only check the hosts if the main URL is changing.
-            if (urlRequestInfo.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame)
+            case QWebEngineUrlRequestInfo::NavigationTypeLink:
+            case QWebEngineUrlRequestInfo::NavigationTypeTyped:
+            case QWebEngineUrlRequestInfo::NavigationTypeFormSubmitted:
+            case QWebEngineUrlRequestInfo::NavigationTypeRedirect:
+            case QWebEngineUrlRequestInfo::NavigationTypeOther:
             {
-                // Get the request URL.
-                QUrl requestUrl = urlRequestInfo.requestUrl();
-
-                // Reapply the domain settings if the host is changing.
-                if (privacyWebEngineViewPointer->currentHost != requestUrl.host())
+                // Only check the hosts if the main URL is changing.
+                if (urlRequestInfo.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame)
                 {
-                    // Apply domain settings, after which the request will be loaded.  `false` indicates that history is not being navigated.
-                    Q_EMIT applyDomainSettings(requestUrl, false);
-
-                    // Block this copy of the request.
-                    urlRequestInfo.block(true);
+                    // Get the request URL.
+                    QUrl requestUrl = urlRequestInfo.requestUrl();
+
+                    // Reapply the domain settings if the host is changing.
+                    if (privacyWebEngineViewPointer->currentHost != requestUrl.host())
+                    {
+                        // Apply domain settings, after which the request will be loaded.  `false` indicates that history is not being navigated.
+                        Q_EMIT applyDomainSettings(requestUrl, false);
+
+                        // Block this copy of the request.
+                        urlRequestInfo.block(true);
+                    }
                 }
-            }
 
-            break;
-        }
+                break;
+            }
 
-        case QWebEngineUrlRequestInfo::NavigationTypeBackForward:
-        {
-            // Only check the hosts if the main URL is changing.
-            if (urlRequestInfo.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame)
+            case QWebEngineUrlRequestInfo::NavigationTypeBackForward:
             {
-                // Get the request URL.
-                QUrl requestUrl = urlRequestInfo.requestUrl();
-
-                // Reapply the domain settings if the host is changing.
-                if (privacyWebEngineViewPointer->currentHost != requestUrl.host())
+                // Only check the hosts if the main URL is changing.
+                if (urlRequestInfo.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame)
                 {
-                    // Apply domain settings, after which the request will be loaded.  `true` indicates that history is being navigated.
-                    Q_EMIT applyDomainSettings(requestUrl, true);
+                    // Get the request URL.
+                    QUrl requestUrl = urlRequestInfo.requestUrl();
+
+                    // Reapply the domain settings if the host is changing.
+                    if (privacyWebEngineViewPointer->currentHost != requestUrl.host())
+                    {
+                        // Apply domain settings, after which the request will be loaded.  `true` indicates that history is being navigated.
+                        Q_EMIT applyDomainSettings(requestUrl, true);
+                    }
                 }
+
+                break;
             }
 
-            break;
+            default:
+            {
+                // Do nothing.
+                break;
+            }
         }
-
-        default:
-            // Do nothing.
-            break;
     }
 
     // Send the request struct to the privacy WebEngine view.