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

Issue 5690: Add key for brave services #3198

Merged
merged 1 commit into from
Oct 16, 2019
Merged

Issue 5690: Add key for brave services #3198

merged 1 commit into from
Oct 16, 2019

Conversation

jumde
Copy link
Contributor

@jumde jumde commented Aug 16, 2019

Fix brave/brave-browser#5690

Submitter Checklist:

Test Plan:

  1. Open Fiddler and enable SSL proxying: Settings > HTTPS > Decrypt HTTPS Traffic
  2. Download the root cert and enable trust for the cert using Keychain Access
  3. Verify that all requests to *.brave.com have the header `BraveServiceKey: dummytoken

Services:

  • crlsets.brave.com
  • redirector.brave.com
  • go-updater.brave.com
  • static.brave.com
  • static1.brave.com
  • clients4.brave.com
  • componentupdater.brave.com
  • crxdownload.brave.com
  • extensionupdater.brave.com
  • safebrowsing.brave.com
  • brave-core-ext.s3.brave.com

Remaining proxies are currently blocked on: brave/brave-browser#6331

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

After-merge Checklist:

  • The associated issue milestone is set to the smallest version that the
    changes has landed on.
  • All relevant documentation has been updated.

@jumde jumde self-assigned this Aug 16, 2019
@jumde jumde changed the title Issue 5690: Add key for brave services [WIP] Issue 5690: Add key for brave services Aug 16, 2019
@jumde jumde changed the title [WIP] Issue 5690: Add key for brave services Issue 5690: Add key for brave services Aug 16, 2019
@jumde jumde changed the title Issue 5690: Add key for brave services [WIP] Issue 5690: Add key for brave services Aug 19, 2019
@jumde jumde changed the title [WIP] Issue 5690: Add key for brave services Issue 5690: Add key for brave services Aug 20, 2019
@@ -8,13 +8,35 @@
#include <memory>
#include <vector>

#include "base/strings/stringprintf.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

?

static URLPattern proxy_pattern(URLPattern::SCHEME_HTTP |
URLPattern::SCHEME_HTTPS, kBraveProxyPattern);

if (proxy_pattern.MatchesURL(ctx->request_url)) {
Copy link
Collaborator

@bridiver bridiver Aug 20, 2019

Choose a reason for hiding this comment

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

I'm not sure this is a viable method to use anymore for headers with network service - cc @iefremov

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm also not sure this was ever really the right place to add headers

Copy link
Contributor

Choose a reason for hiding this comment

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

why not? I tested OnBeforeStartTransaction_SiteHacksWork and it worked for UA overriding. It should be safe for non-restricted headers (Cookies, Referer, etc)

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's definitely not the right place for UA overriding because there are methods specifically for that. The other method I was thinking of was NavigationHandle::SetRequestHeaders but that only works for main/subframe navigations

@jumde jumde changed the title Issue 5690: Add key for brave services [WIP] Issue 5690: Add key for brave services Aug 20, 2019
@jumde jumde force-pushed the keyed_apis branch 3 times, most recently from 4548cb6 to 70a808f Compare August 20, 2019 22:42
namespace brave {

void AddBraveServicesKeyHeader(network::ResourceRequest* url_request) {
static URLPattern proxy_pattern(URLPattern::SCHEME_HTTP |
Copy link
Member

Choose a reason for hiding this comment

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

Do we need HTTP here? I'm pretty sure all of our proxies are HTTPS only.

@@ -5,6 +5,7 @@

#include "brave/common/network_constants.h"

const char kBraveProxyPattern[] = "*://*.brave.com/*";
Copy link
Member

Choose a reason for hiding this comment

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

This could be https://*.brave.com/* I think.

@jumde jumde force-pushed the keyed_apis branch 2 times, most recently from 49cc058 to 14bbc69 Compare September 30, 2019 16:57
@jumde jumde force-pushed the keyed_apis branch 3 times, most recently from 0d48e43 to 9771069 Compare October 8, 2019 00:35
@jumde jumde changed the title [WIP] Issue 5690: Add key for brave services Issue 5690: Add key for brave services Oct 8, 2019
@jumde jumde force-pushed the keyed_apis branch 3 times, most recently from f07fe4d to e9a934c Compare October 8, 2019 15:08

defines = []
if (brave_services_key != "") {
defines += [ "BRAVE_SERVICES_KEY=\"$brave_services_key\"" ]
Copy link
Contributor

Choose a reason for hiding this comment

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

mind adding a comment describing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

#include "services/network/public/cpp/resource_request.h"
#include "url/gurl.h"

#if !defined(BRAVE_SERVICES_KEY)
#define BRAVE_SERVICES_KEY "dummytoken"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to see some comments here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

kBraveProxyPattern);
if (proxy_pattern.MatchesURL(url_request->url)) {
url_request->headers.SetHeaderIfMissing(kBraveServicesKeyHeader,
BRAVE_SERVICES_KEY);
Copy link
Contributor

Choose a reason for hiding this comment

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

clang-format

@@ -0,0 +1,62 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a browser test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

net::TestURLRequestContext* context() { return context_.get(); }

private:
content::TestBrowserThreadBundle thread_bundle_;
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to me that we don't need all this stuff for simple tests

Copy link
Contributor

@iefremov iefremov left a comment

Choose a reason for hiding this comment

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

There are some minors

@jumde jumde force-pushed the keyed_apis branch 7 times, most recently from 2327e50 to 117d8a4 Compare October 14, 2019 16:41
iefremov
iefremov previously approved these changes Oct 14, 2019

void SetUpOnMainThread() override {
host_resolver()->AddRule("*", "127.0.0.1");
EXPECT_TRUE(https_server_.Start());
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd use ASSERT_TRUE

return loader_factory_;
}

void SetUp() override { InProcessBrowserTest::SetUp(); }
Copy link
Contributor

Choose a reason for hiding this comment

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

Unneeded?

->GetSharedURLLoaderFactory();
}

bool LoadURL(std::string host) {
Copy link
Contributor

Choose a reason for hiding this comment

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

const std::string& or base::StringPiece

}

bool LoadURL(std::string host) {
std::unique_ptr<network::ResourceRequest> request =
Copy link
Contributor

Choose a reason for hiding this comment

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

auto here and below

scoped_refptr<network::SharedURLLoaderFactory> loader_factory_ = nullptr;
};

IN_PROC_BROWSER_TEST_F(SystemNetworkContextManagerBrowsertest,
Copy link
Contributor

Choose a reason for hiding this comment

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

Many thanks for making the test!


namespace brave {

class BraveSystemRequestHandlerTest : public testing::Test {
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need to have an empty class, just use TEST(BraveSystemRequestHandlerTest, AddBraveServiceKeyHeader) for tests

};

TEST_F(BraveSystemRequestHandlerTest, AddBraveServiceKeyHeader) {
GURL url("https://demo.brave.com");
Copy link
Contributor

Choose a reason for hiding this comment

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

clang-format

};

TEST_F(BraveSystemRequestHandlerTest, AddBraveServiceKeyHeader) {
GURL url("https://demo.brave.com");
Copy link
Contributor

Choose a reason for hiding this comment

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

const GURL


#include "brave/browser/net/url_context.h"
#include "brave/common/network_constants.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

most of includes are not needed - these three below and url_context.h

@jumde jumde merged commit 869deea into master Oct 16, 2019
@jumde jumde added this to the 0.73.x - Nightly milestone Oct 17, 2019
@jumde jumde deleted the keyed_apis branch October 23, 2019 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add key for brave services
4 participants