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 10269: Do not proxy downloads for Widevine (uplift to 1.10.x) #5874

Merged
merged 1 commit into from
Jun 17, 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
16 changes: 14 additions & 2 deletions browser/net/brave_static_redirect_network_delegate_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ int OnBeforeURLRequest_StaticRedirectWorkForGURL(
kSafeBrowsingPrefix);
static URLPattern safebrowsingfilecheck_pattern(URLPattern::SCHEME_HTTPS,
kSafeBrowsingFileCheckPrefix);

// To-Do (@jumde) - Update the naming for the variables below
// https://github.com/brave/brave-browser/issues/10314
static URLPattern crlSet_pattern1(
URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS, kCRLSetPrefix1);
static URLPattern crlSet_pattern2(
Expand All @@ -54,6 +57,13 @@ int OnBeforeURLRequest_StaticRedirectWorkForGURL(
URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS,
"*://dl.google.com/*");

static URLPattern widevine_gvt1_pattern(
URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS,
kWidevineGvt1Prefix);
static URLPattern widevine_google_dl_pattern(
URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS,
kWidevineGoogleDlPrefix);

#if BUILDFLAG(ENABLE_BRAVE_TRANSLATE_GO)
static URLPattern translate_pattern(URLPattern::SCHEME_HTTPS,
kTranslateElementJSPattern);
Expand Down Expand Up @@ -123,14 +133,16 @@ int OnBeforeURLRequest_StaticRedirectWorkForGURL(
return net::OK;
}

if (gvt1_pattern.MatchesURL(request_url)) {
if (gvt1_pattern.MatchesURL(request_url) &&
!widevine_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)) {
if (googleDl_pattern.MatchesURL(request_url) &&
!widevine_google_dl_pattern.MatchesURL(request_url)) {
replacements.SetSchemeStr("https");
replacements.SetHostStr(kBraveRedirectorProxy);
*new_url = request_url.ReplaceComponents(replacements);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <memory>
#include <string>

#include "base/strings/string_util.h"
#include "brave/browser/net/url_context.h"
#include "brave/browser/translate/buildflags/buildflags.h"
#include "brave/common/network_constants.h"
Expand Down Expand Up @@ -238,6 +239,33 @@ TEST(BraveStaticRedirectNetworkDelegateHelperTest, ModifyGoogleDl) {
EXPECT_EQ(rc, net::OK);
}

TEST(BraveStaticRedirectNetworkDelegateHelperTest, DontModifyGvt1ForWidevine) {
const GURL url(
"http://r2---sn-n4v7sn7y.gvt1.com/edgedl/chromewebstore/"
"L2Nocm9tZV9leHRlbnNpb24vYmxvYnMvYjYxQUFXaFBmeUtPbVFUYUh"
"mRGV0MS1Wdw/4.10.1610.0_oimompecagnajdejgnnjijobebaeigek"
".crx");
auto request_info = std::make_shared<brave::BraveRequestInfo>(url);
int rc =
OnBeforeURLRequest_StaticRedirectWork(ResponseCallback(), request_info);
EXPECT_EQ(request_info->new_url_spec, "");
EXPECT_EQ(rc, net::OK);
}

TEST(BraveStaticRedirectNetworkDelegateHelperTest,
DontModifyGoogleDlForWidevine) {
const GURL url(
"http://dl.google.com/edgedl/chromewebstore/"
"L2Nocm9tZV9leHRlbnNpb24vYmxvYnMvYjYxQUFXaFBmeUtPbVFUYUh"
"mRGV0MS1Wdw/4.10.1610.0_oimompecagnajdejgnnjijobebaeigek"
".crx");
auto request_info = std::make_shared<brave::BraveRequestInfo>(url);
int rc =
OnBeforeURLRequest_StaticRedirectWork(ResponseCallback(), request_info);
EXPECT_EQ(request_info->new_url_spec, "");
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
6 changes: 6 additions & 0 deletions common/network_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ const char kCRLSetPrefix4[] =
"/*crxd";
const char kChromeCastPrefix[] =
"*://*.gvt1.com/edgedl/chromewebstore/*pkedcjkdefgpdelpbcmbmeomcjbeemfm*";

const char kWidevineGvt1Prefix[] =
"*://*.gvt1.com/*oimompecagnajdejgnnjijobebaeigek*";
const char kWidevineGoogleDlPrefix[] =
"*://dl.google.com/*oimompecagnajdejgnnjijobebaeigek*";

const char kForbesPattern[] = "https://www.forbes.com/*";
const char kForbesExtraCookies[] =
"forbes_ab=true; welcomeAd=true; adblock_session=Off; "
Expand Down
2 changes: 2 additions & 0 deletions common/network_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ extern const char kCRLSetPrefix4[];
extern const char kChromeCastPrefix[];
extern const char kTwitterPattern[];
extern const char kGoogleOAuthPattern[];
extern const char kWidevineGvt1Prefix[];
extern const char kWidevineGoogleDlPrefix[];

extern const char kCookieHeader[];
extern const char kRefererHeader[];
Expand Down