Skip to content

Commit

Permalink
Tie query filter to site's Shields setting (fixes brave/brave-browser…
Browse files Browse the repository at this point in the history
  • Loading branch information
fmarier committed Feb 18, 2021
1 parent e3d28f7 commit 3416c25
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions browser/net/brave_site_hacks_network_delegate_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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[] = {
Expand Down

0 comments on commit 3416c25

Please sign in to comment.