Skip to content

Commit

Permalink
Merge pull request #5846 from brave/widevine_download_exception
Browse files Browse the repository at this point in the history
Fix 10269: Do not proxy downloads for Widevine
  • Loading branch information
jumde authored Jun 16, 2020
2 parents 04f9921 + bdaa1f8 commit 7d4f423
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
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 @@ -56,6 +56,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 @@ -74,6 +77,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 @@ -144,14 +154,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 @@ -240,6 +241,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 @@ -50,6 +50,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 @@ -38,6 +38,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

0 comments on commit 7d4f423

Please sign in to comment.