-
Notifications
You must be signed in to change notification settings - Fork 887
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filter user-tracking parameters from query string (fixes brave/brave-…
…browser#4239) If a URL's query string includes one of the parameter names known to track individual users, we remove them. We essentially apply the following to the query string: s/&(fbclid|gclid|msclkid|mc_eid)=[^&]+//g s/^(fbclid|gclid|msclkid|mc_eid)=[^&]+&//g s/^(fbclid|gclid|msclkid|mc_eid)=[^&]+$//g https://support.google.com/analytics/answer/7519794 https://stackoverflow.com/questions/52847475/what-is-fbclid-the-new-facebook-parameter https://about.ads.microsoft.com/en-us/blog/post/january-2018/conversion-tracking-update-on-bing-ads https://developer.mailchimp.com/documentation/mailchimp/guides/getting-started-with-ecommerce/#e-commerce-tracking-and-reports
- Loading branch information
Showing
3 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
#include <memory> | ||
#include <string> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "brave/browser/net/url_context.h" | ||
|
@@ -203,4 +204,85 @@ TEST_F(BraveSiteHacksNetworkDelegateHelperTest, | |
}); | ||
} | ||
|
||
TEST_F(BraveSiteHacksNetworkDelegateHelperTest, QueryStringUntouched) { | ||
const std::vector<const std::string> urls({ | ||
"https://example.com/", | ||
"https://example.com/?", | ||
"https://example.com/?+%20", | ||
"https://user:[email protected]/path/file.html?foo=1#fragment", | ||
"http://user:[email protected]/path/file.html?foo=1&bar=2#fragment", | ||
"https://example.com/?file=https%3A%2F%2Fexample.com%2Ftest.pdf", | ||
"https://example.com/?title=1+2&caption=1%202", | ||
"https://example.com/?foo=1&&bar=2#fragment", | ||
"https://example.com/?foo&bar=&#fragment", | ||
"https://example.com/?foo=1&fbcid=no&gcid=no&mc_cid=no&bar=&#frag", | ||
"https://example.com/?fbclid=&gclid&=mc_eid&msclkid=", | ||
"https://example.com/?value=fbclid=1¬-gclid=2&foo+mc_eid=3", | ||
"https://example.com/?+fbclid=1", | ||
"https://example.com/?%20fbclid=1", | ||
"https://example.com/#fbclid=1", | ||
}); | ||
for (const auto& url : urls) { | ||
net::TestDelegate test_delegate; | ||
std::unique_ptr<net::URLRequest> request = context()->CreateRequest( | ||
GURL(url), net::IDLE, &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS); | ||
|
||
std::shared_ptr<brave::BraveRequestInfo> brave_request_info( | ||
new brave::BraveRequestInfo()); | ||
brave::BraveRequestInfo::FillCTXFromRequest(request.get(), | ||
brave_request_info); | ||
brave::ResponseCallback callback; | ||
int ret = | ||
brave::OnBeforeURLRequest_SiteHacksWork(callback, brave_request_info); | ||
EXPECT_EQ(ret, net::OK); | ||
// new_url should not be set | ||
EXPECT_TRUE(brave_request_info->new_url_spec.empty()); | ||
EXPECT_EQ(request->url(), GURL(url)); | ||
} | ||
} | ||
|
||
TEST_F(BraveSiteHacksNetworkDelegateHelperTest, QueryStringFiltered) { | ||
const std::vector<const std::pair<const std::string, const std::string>> urls( | ||
{ | ||
// { original url, expected url after filtering } | ||
{"https://example.com/?fbclid=1234", "https://example.com/"}, | ||
{"https://example.com/?fbclid=1234&", "https://example.com/"}, | ||
{"https://example.com/?&fbclid=1234", "https://example.com/"}, | ||
{"https://example.com/?gclid=1234", "https://example.com/"}, | ||
{"https://example.com/?fbclid=0&gclid=1&msclkid=a&mc_eid=a1", | ||
"https://example.com/"}, | ||
{"https://example.com/?fbclid=&foo=1&bar=2&gclid=abc", | ||
"https://example.com/?fbclid=&foo=1&bar=2"}, | ||
{"https://example.com/?fbclid=&foo=1&gclid=1234&bar=2", | ||
"https://example.com/?fbclid=&foo=1&bar=2"}, | ||
{"http://u:[email protected]/path/file.html?foo=1&fbclid=abcd#fragment", | ||
"http://u:[email protected]/path/file.html?foo=1#fragment"}, | ||
// Obscure edge cases that break most parsers: | ||
{"https://example.com/?fbclid&foo&&gclid=2&bar=&%20", | ||
"https://example.com/?fbclid&foo&&bar=&%20"}, | ||
{"https://example.com/?fbclid=1&1==2&=msclkid&foo=bar&&a=b=c&", | ||
"https://example.com/?1==2&=msclkid&foo=bar&&a=b=c&"}, | ||
{"https://example.com/?fbclid=1&=2&?foo=yes&bar=2+", | ||
"https://example.com/?=2&?foo=yes&bar=2+"}, | ||
{"https://example.com/?fbclid=1&a+b+c=some%20thing&1%202=3+4", | ||
"https://example.com/?a+b+c=some%20thing&1%202=3+4"}, | ||
}); | ||
for (const auto& pair : urls) { | ||
net::TestDelegate test_delegate; | ||
std::unique_ptr<net::URLRequest> request = | ||
context()->CreateRequest(GURL(pair.first), net::IDLE, &test_delegate, | ||
TRAFFIC_ANNOTATION_FOR_TESTS); | ||
|
||
std::shared_ptr<brave::BraveRequestInfo> brave_request_info( | ||
new brave::BraveRequestInfo()); | ||
brave::BraveRequestInfo::FillCTXFromRequest(request.get(), | ||
brave_request_info); | ||
brave::ResponseCallback callback; | ||
int ret = | ||
brave::OnBeforeURLRequest_SiteHacksWork(callback, brave_request_info); | ||
EXPECT_EQ(ret, net::OK); | ||
EXPECT_EQ(brave_request_info->new_url_spec, pair.second); | ||
} | ||
} | ||
|
||
} // namespace |