Skip to content

Commit

Permalink
Merge pull request #108 from brave/safebrowsing_proxy
Browse files Browse the repository at this point in the history
Setting proxy for safe browsing requests
  • Loading branch information
bbondy authored May 22, 2018
2 parents bb2a6cb + 8e17506 commit 7698bd0
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 2 deletions.
5 changes: 4 additions & 1 deletion browser/net/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import("//build/config/features.gni")

source_set("net") {
configs += [ "//brave/build/geolocation" ]
configs += [
"//brave/build/geolocation",
"//brave/build/safebrowsing"
]
sources = [
"brave_network_delegate_base.cc",
"brave_network_delegate_base.h",
Expand Down
11 changes: 10 additions & 1 deletion browser/net/brave_static_redirect_network_delegate_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,22 @@ int OnBeforeURLRequest_StaticRedirectWork(
GURL* new_url,
const ResponseCallback& next_callback,
std::shared_ptr<BraveRequestInfo> ctx) {
GURL::Replacements replacements;
static URLPattern geo_pattern(URLPattern::SCHEME_HTTPS, kGeoLocationsPattern);
static URLPattern safeBrowsing_pattern(URLPattern::SCHEME_HTTPS, kSafeBrowsingPrefix);

if (geo_pattern.MatchesURL(request->url())) {
*new_url = GURL(GOOGLEAPIS_ENDPOINT GOOGLEAPIS_API_KEY);
return net::OK;
}

if (safeBrowsing_pattern.MatchesHost(request->url())) {
replacements.SetHostStr(SAFEBROWSING_ENDPOINT);
*new_url = request->url().ReplaceComponents(replacements);
return net::OK;
}

if (IsUpdaterURL(request->url())) {
GURL::Replacements replacements;
replacements.SetQueryStr(request->url().query_piece());
*new_url = GURL(kBraveUpdatesExtensionsEndpoint).ReplaceComponents(replacements);
return net::OK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,47 @@ TEST_F(BraveStaticRedirectNetworkDelegateHelperTest, ModifyGeoURL) {
EXPECT_EQ(ret, net::OK);
}

TEST_F(BraveStaticRedirectNetworkDelegateHelperTest, ModifySafeBrowsingURLV4) {
net::TestDelegate test_delegate;
GURL url("https://safebrowsing.googleapis.com/v4/threatListUpdates:fetch?$req=ChkKCGNocm9taXVtEg02Ni");
std::unique_ptr<net::URLRequest> request =
context()->CreateRequest(url, net::IDLE, &test_delegate,
TRAFFIC_ANNOTATION_FOR_TESTS);
std::shared_ptr<brave::BraveRequestInfo>
before_url_context(new brave::BraveRequestInfo());
brave::ResponseCallback callback;
GURL new_url;
GURL::Replacements replacements;
replacements.SetHostStr(SAFEBROWSING_ENDPOINT);
GURL expected_url(url.ReplaceComponents(replacements));
int ret =
OnBeforeURLRequest_StaticRedirectWork(request.get(), &new_url, callback,
before_url_context);
EXPECT_EQ(new_url, expected_url);
EXPECT_EQ(ret, net::OK);
}

TEST_F(BraveStaticRedirectNetworkDelegateHelperTest, ModifySafeBrowsingURLV5) {
net::TestDelegate test_delegate;
GURL url("https://safebrowsing.googleapis.com/v5/threatListUpdates:fetch?$req=ChkKCGNocm9taXVtEg02Ni");
std::unique_ptr<net::URLRequest> request =
context()->CreateRequest(url, net::IDLE, &test_delegate,
TRAFFIC_ANNOTATION_FOR_TESTS);
std::shared_ptr<brave::BraveRequestInfo>
before_url_context(new brave::BraveRequestInfo());
brave::ResponseCallback callback;
GURL new_url;
GURL::Replacements replacements;
replacements.SetHostStr(SAFEBROWSING_ENDPOINT);
GURL expected_url(url.ReplaceComponents(replacements));
int ret =
OnBeforeURLRequest_StaticRedirectWork(request.get(), &new_url, callback,
before_url_context);
EXPECT_EQ(new_url, expected_url);
EXPECT_EQ(ret, net::OK);
}


TEST_F(BraveStaticRedirectNetworkDelegateHelperTest, ModifyComponentUpdaterURL) {
net::TestDelegate test_delegate;
std::string query_string("?foo=bar");
Expand Down
9 changes: 9 additions & 0 deletions build/safebrowsing/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare_args() {
safebrowsing_api_endpoint = ""
}

config("safebrowsing") {
defines = [
"SAFEBROWSING_ENDPOINT=\"$safebrowsing_api_endpoint\""
]
}
1 change: 1 addition & 0 deletions common/network_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const char kBraveUpdatesExtensionsEndpoint[] = "https://laptop-updates.brave.com
const char kEmptyDataURI[] = "data:application/javascript;base64,MA==";
const char kJSDataURLPrefix[] = "data:application/javascript;base64,";
const char kGeoLocationsPattern[] = "https://www.googleapis.com/geolocation/v1/geolocate?key=*";
const char kSafeBrowsingPrefix[] = "https://safebrowsing.googleapis.com/";
const char kGoogleTagManagerPattern[] = "https://www.googletagmanager.com/gtm.js";
const char kGoogleTagServicesPattern[] = "https://www.googletagservices.com/tag/js/gpt.js";
const char kForbesPattern[] = "https://www.forbes.com/*";
Expand Down
1 change: 1 addition & 0 deletions common/network_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extern const char kGoogleTagManagerPattern[];
extern const char kGoogleTagServicesPattern[];
extern const char kForbesPattern[];
extern const char kForbesExtraCookies[];
extern const char kSafeBrowsingPrefix[];
extern const char kTwitterPattern[];
extern const char kTwitterReferrer[];
extern const char kTwitterRedirectURL[];
Expand Down
1 change: 1 addition & 0 deletions test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ test("brave_unit_tests") {

configs += [
"//brave/build/geolocation",
"//brave/build/safebrowsing",
]

public_deps = [
Expand Down

0 comments on commit 7698bd0

Please sign in to comment.