Skip to content

Commit

Permalink
Hide Uphold linking flow from webRequest (brave/brave-browser#4928)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmarier committed Jul 17, 2019
1 parent 757a6b6 commit 2efb4e6
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 1 deletion.
3 changes: 3 additions & 0 deletions browser/extensions/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ source_set("extensions") {
sources = [
"api/rewards_notifications_api.cc",
"api/rewards_notifications_api.h",
"api/brave_extensions_api_client.cc",
"api/brave_extensions_api_client.h",
"api/brave_rewards_api.cc",
"api/brave_rewards_api.h",
"api/brave_shields_api.cc",
Expand Down Expand Up @@ -59,6 +61,7 @@ source_set("extensions") {
"//brave/components/brave_sync",
"//brave/components/brave_sync:generated_resources",
"//brave/components/brave_sync:static_resources",
"//brave/extensions/common",
"//components/prefs",
"//components/update_client:patch_impl",
"//components/update_client:unzip_impl",
Expand Down
22 changes: 22 additions & 0 deletions browser/extensions/api/brave_extensions_api_client.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/browser/extensions/api/brave_extensions_api_client.h"

#include "brave/extensions/common/brave_extension_urls.h"

namespace extensions {

bool BraveExtensionsAPIClient::ShouldHideBrowserNetworkRequest(
const WebRequestInfo& request) const {
const GURL& url = request.url;
if (extension_urls::IsBraveProtectedUrl(url::Origin::Create(url),
url.path_piece())) {
return true;
}
return ChromeExtensionsAPIClient::ShouldHideBrowserNetworkRequest(request);
}

} // namespace extensions
21 changes: 21 additions & 0 deletions browser/extensions/api/brave_extensions_api_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_EXTENSIONS_API_BRAVE_EXTENSIONS_API_CLIENT_H_
#define BRAVE_BROWSER_EXTENSIONS_API_BRAVE_EXTENSIONS_API_CLIENT_H_

#include "chrome/browser/extensions/api/chrome_extensions_api_client.h"
#include "extensions/browser/api/web_request/web_request_info.h"

namespace extensions {

class BraveExtensionsAPIClient : public ChromeExtensionsAPIClient {
bool ShouldHideBrowserNetworkRequest(
const WebRequestInfo& request) const override;
};

} // namespace extensions

#endif // BRAVE_BROWSER_EXTENSIONS_API_BRAVE_EXTENSIONS_API_CLIENT_H_
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
// Copyright (c) 2019 The Brave Authors. All rights reserved.
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/browser/extensions/api/brave_extensions_api_client.h"
#include "brave/browser/extensions/updater/brave_update_client_config.h"
#include "chrome/browser/extensions/chrome_extensions_browser_client.h"
#include "chrome/browser/extensions/updater/chrome_update_client_config.h"

#define ChromeUpdateClientConfig BraveUpdateClientConfig
#define ChromeExtensionsAPIClient BraveExtensionsAPIClient
#include "../../../../../chrome/browser/extensions/chrome_extensions_browser_client.cc" // NOLINT
#undef ChromeUpdateClientConfig
#undef ChromeExtensionsAPIClient
12 changes: 12 additions & 0 deletions extensions/common/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
source_set("common") {
sources = [
"brave_extension_urls.cc",
"brave_extension_urls.h",
]

deps = [
"//base",
"//extensions/common",
"//url",
]
}
23 changes: 23 additions & 0 deletions extensions/common/brave_extension_urls.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/extensions/common/brave_extension_urls.h"

#include "base/strings/string_util.h"
#include "url/origin.h"

namespace extension_urls {

bool IsBraveProtectedUrl(const url::Origin& origin, base::StringPiece path) {
return ((origin.DomainIs("sandbox.uphold.com") ||
origin.DomainIs("uphold.com")) &&
base::StartsWith(path, "/authorize/",
base::CompareCase::SENSITIVE)) ||
(origin.DomainIs("api.uphold.com") &&
base::StartsWith(path, "/oauth2/token",
base::CompareCase::SENSITIVE));
}

} // namespace extension_urls
18 changes: 18 additions & 0 deletions extensions/common/brave_extension_urls.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_EXTENSIONS_COMMON_EXTENSION_URLS_H_
#define BRAVE_EXTENSIONS_COMMON_EXTENSION_URLS_H_

#include "extensions/common/extension_urls.h"

namespace extension_urls {

// Returns true if the URL points to a security-critical service.
bool IsBraveProtectedUrl(const url::Origin& origin, base::StringPiece path);

} // namespace extension_urls

#endif // BRAVE_EXTENSIONS_COMMON_EXTENSION_URLS_H_

0 comments on commit 2efb4e6

Please sign in to comment.