Tie query filter to site's Shields setting (fixes brave/brave-browser#13242)

This commit is contained in:
Francois Marier
2021-02-17 18:28:46 -08:00
parent e3d28f73ea
commit 3416c25922
2 changed files with 28 additions and 0 deletions
@@ -94,6 +94,11 @@ DECLARE_LAZY_MATCHER(tracker_appended_matcher,
void ApplyPotentialQueryStringFilter(std::shared_ptr<BraveRequestInfo> ctx) {
SCOPED_UMA_HISTOGRAM_TIMER("Brave.SiteHacks.QueryFilter");
if (!ctx->allow_brave_shields) {
// Don't apply the filter if the destination URL has shields down.
return;
}
if (ctx->redirect_source.is_valid()) {
if (ctx->internal_redirect) {
// Ignore internal redirects since we trigger them.
@@ -7,9 +7,13 @@
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
#include "brave/common/brave_paths.h"
#include "brave/components/brave_shields/browser/brave_shields_util.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/network_session_configurator/common/network_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
@@ -46,6 +50,10 @@ class BraveSiteHacksNetworkDelegateBrowserTest : public InProcessBrowserTest {
https_server_.GetURL("sub.a.com", "/navigate-to-site.html");
}
HostContentSettingsMap* content_settings() {
return HostContentSettingsMapFactory::GetForProfile(browser()->profile());
}
void SetUpCommandLine(base::CommandLine* command_line) override {
InProcessBrowserTest::SetUpCommandLine(command_line);
// This is needed to load pages from "domain.com" without an interstitial.
@@ -141,6 +149,21 @@ IN_PROC_BROWSER_TEST_F(BraveSiteHacksNetworkDelegateBrowserTest,
}
}
IN_PROC_BROWSER_TEST_F(BraveSiteHacksNetworkDelegateBrowserTest,
QueryStringFilterShieldsDown) {
const std::string inputs[] = {
"", "foo=bar", "fbclid=1", "fbclid=2&key=value", "key=value&fbclid=3",
};
constexpr size_t input_count = base::size(inputs);
for (size_t i = 0; i < input_count; i++) {
const GURL dest_url = landing_url(inputs[i], simple_landing_url());
brave_shields::SetBraveShieldsEnabled(content_settings(), false, dest_url);
NavigateToURLAndWaitForRedirects(url(dest_url, cross_site_url()), dest_url);
}
}
IN_PROC_BROWSER_TEST_F(BraveSiteHacksNetworkDelegateBrowserTest,
QueryStringFilterSameSite) {
const std::string inputs[] = {