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

Setting proxy for safe browsing requests #108

Merged
merged 1 commit into from
May 22, 2018
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
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",
Copy link
Collaborator

@bridiver bridiver May 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that using configs like this is the best way to do this. I think it would be better to create a normal dependency //brave/browser/safe_browsing and give it a public config. That would be a more typical pattern.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw - my reasoning for this is that a dep provides more flexibility to manage configs, sources and add any additional deps that might be required in the future. In most cases (there are some exceptions), configs are treated more like internal implementation details for deps and those details are passed along using public_configs

"//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 @@ -42,6 +42,7 @@ test("brave_unit_tests") {

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

public_deps = [
Expand Down