Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 7976: Adding a proxy for Crowd Deny (uplift to 1.4.x) #4527

Merged
merged 1 commit into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions browser/net/brave_static_redirect_network_delegate_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ int OnBeforeURLRequest_StaticRedirectWorkForGURL(
URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS, kCRXDownloadPrefix);
static URLPattern autofill_pattern(
URLPattern::SCHEME_HTTPS, kAutofillPrefix);
static URLPattern gvt1_pattern(
URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS, "*://*.gvt1.com/*");
static URLPattern googleDl_pattern(
URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS,
"*://dl.google.com/*");

#if BUILDFLAG(ENABLE_BRAVE_TRANSLATE_GO)
static URLPattern translate_pattern(URLPattern::SCHEME_HTTPS,
Expand Down Expand Up @@ -117,6 +122,21 @@ int OnBeforeURLRequest_StaticRedirectWorkForGURL(
*new_url = request_url.ReplaceComponents(replacements);
return net::OK;
}

if (gvt1_pattern.MatchesURL(request_url)) {
replacements.SetSchemeStr("https");
replacements.SetHostStr(kBraveRedirectorProxy);
*new_url = request_url.ReplaceComponents(replacements);
return net::OK;
}

if (googleDl_pattern.MatchesURL(request_url)) {
replacements.SetSchemeStr("https");
replacements.SetHostStr(kBraveRedirectorProxy);
*new_url = request_url.ReplaceComponents(replacements);
return net::OK;
}

#if BUILDFLAG(ENABLE_BRAVE_TRANSLATE_GO)
if (translate_pattern.MatchesURL(request_url)) {
replacements.SetQueryStr(request_url.query_piece());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,36 @@ TEST(BraveStaticRedirectNetworkDelegateHelperTest, ModifySafeBrowsingURLV5) {
EXPECT_EQ(rc, net::OK);
}

TEST(BraveStaticRedirectNetworkDelegateHelperTest, ModifyGvt1) {
const GURL url(
"http://redirector.gvt1.com/edgedl/release2/"
"NfaZYtcKdtFc0LUvFkcNFA_0.3/AKveSIjhHAm2K09XAMovFEQ");
const GURL expected_url(
"https://redirector.brave.com/edgedl/release2/"
"NfaZYtcKdtFc0LUvFkcNFA_0.3/AKveSIjhHAm2K09XAMovFEQ");

auto request_info = std::make_shared<brave::BraveRequestInfo>(url);
int rc =
OnBeforeURLRequest_StaticRedirectWork(ResponseCallback(), request_info);
EXPECT_EQ(request_info->new_url_spec, expected_url);
EXPECT_EQ(rc, net::OK);
}

TEST(BraveStaticRedirectNetworkDelegateHelperTest, ModifyGoogleDl) {
const GURL url(
"http://dl.google.com/release2/"
"NfaZYtcKdtFc0LUvFkcNFA_0.3/AKveSIjhHAm2K09XAMovFEQ");
const GURL expected_url(
"https://redirector.brave.com/release2/"
"NfaZYtcKdtFc0LUvFkcNFA_0.3/AKveSIjhHAm2K09XAMovFEQ");

auto request_info = std::make_shared<brave::BraveRequestInfo>(url);
int rc =
OnBeforeURLRequest_StaticRedirectWork(ResponseCallback(), request_info);
EXPECT_EQ(request_info->new_url_spec, expected_url);
EXPECT_EQ(rc, net::OK);
}

// TODO(@fmarier): Re-enable download protection once we have
// truncated the list of metadata that it sends to the server
// (brave/brave-browser#6267).
Expand Down