diff --git a/components/query_filter/utils.cc b/components/query_filter/utils.cc index afc03248597..b0fdbc3cee1 100644 --- a/components/query_filter/utils.cc +++ b/components/query_filter/utils.cc @@ -145,6 +145,17 @@ static const auto kScopedQueryStringTrackers = {"si", {"youtube.com", "youtu.be"}}, }); +// URLs with these hostnames will not be modified by the query filter. +// These are exact match comparisons. Sub-domains are not +// automatically included. +static constexpr auto kExemptedHostnames = + base::MakeFixedFlatSet( + base::sorted_unique, + { + // https://github.com/brave/brave-browser/issues/41134 + "urldefense.com", + }); + bool IsScopedTracker( const std::string_view param_name, const std::string& spec, @@ -241,6 +252,11 @@ std::optional MaybeApplyQueryStringFilter( return std::nullopt; } + if (request_url.has_host() && + kExemptedHostnames.count(request_url.host()) == 1) { + return std::nullopt; + } + if (redirect_source_url.is_valid()) { if (internal_redirect) { // Ignore internal redirects since we trigger them. diff --git a/components/query_filter/utils_unittest.cc b/components/query_filter/utils_unittest.cc index b9b139b636a..d090f30c07a 100644 --- a/components/query_filter/utils_unittest.cc +++ b/components/query_filter/utils_unittest.cc @@ -99,6 +99,14 @@ TEST(BraveQueryFilter, FilterQueryTrackers) { EXPECT_FALSE(query_filter::MaybeApplyQueryStringFilter( GURL("https://brave.com"), GURL("https://brave.com"), GURL("https://test.com/?gclid=123"), "GET", true)); + // Don't filter exempted hostnames + EXPECT_FALSE(query_filter::MaybeApplyQueryStringFilter( + GURL("https://brave.com"), GURL(), + GURL("https://urldefense.com/v3/__https://www.portainer.io/hs/" + "preferences-center/en/" + "direct?utm_campaign=XNF&utm_source=hs_automation&_hsenc=p2&_hsmi=" + "26__;!!MlclJBHn!0eDf-z$"), + "GET", false)); } TEST(BraveQueryFilter, IsScopedTracker) {