Skip to content

Commit

Permalink
Merge pull request #1264 from brave/prevent_brave_scheme_loading_from…
Browse files Browse the repository at this point in the history
…_js-0.58.x

Prevent loading brave scheme url from javascript
  • Loading branch information
bbondy authored Jan 8, 2019
2 parents 1fe0bd3 + a070e52 commit a7bcf88
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</style>
<div class="settings-box">
<div class="start">
$i18n{braveSyncLabel} <a href="brave://sync" target="_blank">brave://sync</a>
$i18n{braveSyncLabel} <a href="chrome://sync" target="_blank">brave://sync</a>
</div>
</div>
</template>
Expand Down
5 changes: 5 additions & 0 deletions chromium_src/chrome/browser/profiles/profile_io_data.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/* 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 http://mozilla.org/MPL/2.0/. */

#include "brave/browser/net/brave_profile_network_delegate.h"
#include "brave/common/url_constants.h"

#include "../../../../../../chrome/browser/profiles/profile_io_data.cc"
10 changes: 10 additions & 0 deletions chromium_src/content/public/common/url_constants.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* 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 http://mozilla.org/MPL/2.0/. */

#include "../../../../../content/public/common/url_constants.cc"

namespace content {
const char kBraveUIScheme[] = "brave";
}

10 changes: 10 additions & 0 deletions chromium_src/content/public/common/url_constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* 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 http://mozilla.org/MPL/2.0/. */

#include "../../../../../content/public/common/url_constants.h"

namespace content {
CONTENT_EXPORT extern const char kBraveUIScheme[];
}

2 changes: 1 addition & 1 deletion patches/chrome-VERSION.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/chrome/VERSION b/chrome/VERSION
index 7e1fcd8ad8afd60392aa08b3008d141b4fabfff3..1b4a00c34567099285c0c72ae1debec155873dda 100644
index 7e1fcd8ad8afd60392aa08b3008d141b4fabfff3..f27a435737b953f52ef64bd6da839d4be965ffa6 100644
--- a/chrome/VERSION
+++ b/chrome/VERSION
@@ -1,4 +1,4 @@
Expand Down
14 changes: 12 additions & 2 deletions patches/chrome-browser-profiles-profile_io_data.cc.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc
index 3bfcba30be1ca17870b85acbc68ae15887f027fe..6a74ea76c00df34b9de30166cc891bba90a18f92 100644
index 3bfcba30be1ca17870b85acbc68ae15887f027fe..b2a7449587219c9171654470ea871af78b44e6d2 100644
--- a/chrome/browser/profiles/profile_io_data.cc
+++ b/chrome/browser/profiles/profile_io_data.cc
@@ -25,6 +25,7 @@
Expand All @@ -10,7 +10,17 @@ index 3bfcba30be1ca17870b85acbc68ae15887f027fe..6a74ea76c00df34b9de30166cc891bba
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
@@ -1000,7 +1001,7 @@ void ProfileIOData::Init(
@@ -663,6 +664,9 @@ bool ProfileIOData::IsHandledProtocol(const std::string& scheme) {
extensions::kExtensionScheme,
#endif
content::kChromeUIScheme,
+#if defined(BRAVE_CHROMIUM_BUILD)
+ kBraveUIScheme,
+#endif
url::kDataScheme,
#if defined(OS_CHROMEOS)
content::kExternalFileScheme,
@@ -1000,7 +1004,7 @@ void ProfileIOData::Init(
std::make_unique<network::URLRequestContextBuilderMojo>();

std::unique_ptr<ChromeNetworkDelegate> chrome_network_delegate(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/content/browser/child_process_security_policy_impl.cc b/content/browser/child_process_security_policy_impl.cc
index 323f85836c334129b94351be360062ad4d4d5c36..3fc6f840cf1e7bf7a65a0f7964e56ee5e86b96b4 100644
--- a/content/browser/child_process_security_policy_impl.cc
+++ b/content/browser/child_process_security_policy_impl.cc
@@ -690,6 +690,9 @@ void ChildProcessSecurityPolicyImpl::GrantWebUIBindings(int child_id,

// Web UI bindings need the ability to request chrome: URLs.
state->second->GrantRequestScheme(kChromeUIScheme);
+#if defined(BRAVE_CHROMIUM_BUILD)
+ state->second->GrantRequestScheme(kBraveUIScheme);
+#endif

// Web UI pages can contain links to file:// URLs.
state->second->GrantRequestScheme(url::kFileScheme);
19 changes: 19 additions & 0 deletions patches/content-renderer-render_thread_impl.cc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc
index f2d704c09e6eb90409d6e8119fe1b7d65f2fbabd..797f8f58fd4dbdeb976bdd9bc61e479d5b50c85c 100644
--- a/content/renderer/render_thread_impl.cc
+++ b/content/renderer/render_thread_impl.cc
@@ -1241,6 +1241,14 @@ void RenderThreadImpl::InitializeWebKit(
}

void RenderThreadImpl::RegisterSchemes() {
+#if defined(BRAVE_CHROMIUM_BUILD)
+ // brave:
+ WebString brave_scheme(WebString::FromASCII(kBraveUIScheme));
+ WebSecurityPolicy::RegisterURLSchemeAsDisplayIsolated(brave_scheme);
+ WebSecurityPolicy::RegisterURLSchemeAsNotAllowingJavascriptURLs(
+ brave_scheme);
+#endif
+
// chrome:
WebString chrome_scheme(WebString::FromASCII(kChromeUIScheme));
WebSecurityPolicy::RegisterURLSchemeAsDisplayIsolated(chrome_scheme);

0 comments on commit a7bcf88

Please sign in to comment.