Skip to content

Commit

Permalink
Exempt internal requests from our custom tampering
Browse files Browse the repository at this point in the history
None of the current hooks we have need to tamper with page using
the internal `chrome://` pages, and only brave_webtorrent needs
the extension scheme.
  • Loading branch information
fmarier committed May 14, 2020
1 parent 0220802 commit 534f3e6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions browser/net/brave_request_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/url_constants.h"
#include "extensions/common/constants.h"

#if BUILDFLAG(ENABLE_BRAVE_REFERRALS)
#include "brave/browser/net/brave_referrals_network_delegate_helper.h"
Expand All @@ -42,6 +44,12 @@
#include "brave/browser/net/brave_translate_redirect_network_delegate_helper.h"
#endif

static bool IsInternalScheme(std::shared_ptr<brave::BraveRequestInfo> ctx) {
DCHECK(ctx);
return ctx->request_url.SchemeIs(extensions::kExtensionScheme) ||
ctx->request_url.SchemeIs(content::kChromeUIScheme);
}

BraveRequestHandler::BraveRequestHandler() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
SetupCallbacks();
Expand Down Expand Up @@ -125,7 +133,7 @@ int BraveRequestHandler::OnBeforeURLRequest(
std::shared_ptr<brave::BraveRequestInfo> ctx,
net::CompletionOnceCallback callback,
GURL* new_url) {
if (before_url_request_callbacks_.empty()) {
if (before_url_request_callbacks_.empty() || IsInternalScheme(ctx)) {
return net::OK;
}
SCOPED_UMA_HISTOGRAM_TIMER("Brave.OnBeforeURLRequest_Handler");
Expand All @@ -140,7 +148,7 @@ int BraveRequestHandler::OnBeforeStartTransaction(
std::shared_ptr<brave::BraveRequestInfo> ctx,
net::CompletionOnceCallback callback,
net::HttpRequestHeaders* headers) {
if (before_start_transaction_callbacks_.empty()) {
if (before_start_transaction_callbacks_.empty() || IsInternalScheme(ctx)) {
return net::OK;
}
ctx->event_type = brave::kOnBeforeStartTransaction;
Expand All @@ -163,7 +171,9 @@ int BraveRequestHandler::OnHeadersReceived(
original_response_headers, override_response_headers);
}

if (headers_received_callbacks_.empty()) {
if (headers_received_callbacks_.empty() &&
!ctx->request_url.SchemeIs(content::kChromeUIScheme)) {
// Extension scheme not excluded since brave_webtorrent needs it.
return net::OK;
}

Expand Down

0 comments on commit 534f3e6

Please sign in to comment.