Skip to content

Commit

Permalink
Nullify Origin header in xorigin CORS requests from .onion (fixes bra…
Browse files Browse the repository at this point in the history
  • Loading branch information
fmarier committed Nov 19, 2021
1 parent 5f931c8 commit 1784f7b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions chromium_src/services/network/cors/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_rules = [
"+../../../../../services/network/cors",
]
18 changes: 18 additions & 0 deletions chromium_src/services/network/cors/cors_url_loader.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* Copyright 2021 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/. */

// Nullify the Origin header for cross-origin CORS requests
// originating from a .onion address.
#define BRAVE_CORS_URL_LOADER_START_REQUEST \
if (base::EndsWith(request_.request_initiator->host(), ".onion", \
base::CompareCase::INSENSITIVE_ASCII) && \
!request_.request_initiator->IsSameOriginWith( \
url::Origin::Create(request_.url))) { \
request_.headers.SetHeader(net::HttpRequestHeaders::kOrigin, \
url::Origin().Serialize()); \
} else /* NOLINT */

#include "../../../../../services/network/cors/cors_url_loader.cc"
#undef BRAVE_CORS_URL_LOADER_START_REQUEST
12 changes: 12 additions & 0 deletions patches/services-network-cors-cors_url_loader.cc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/services/network/cors/cors_url_loader.cc b/services/network/cors/cors_url_loader.cc
index dbacb3e96d1f46a6e5eb5080c69a7bb67058e27c..abb62f7cab19343998c3cd9d313348a5b0220bc6 100644
--- a/services/network/cors/cors_url_loader.cc
+++ b/services/network/cors/cors_url_loader.cc
@@ -528,6 +528,7 @@ void CorsURLLoader::StartRequest() {
(fetch_cors_flag_ ||
(request_.method != net::HttpRequestHeaders::kGetMethod &&
request_.method != net::HttpRequestHeaders::kHeadMethod))) {
+ BRAVE_CORS_URL_LOADER_START_REQUEST
if (tainted_) {
request_.headers.SetHeader(net::HttpRequestHeaders::kOrigin,
url::Origin().Serialize());

0 comments on commit 1784f7b

Please sign in to comment.