Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Unified Diff: content/browser/frame_host/data_url_navigation_throttle.cc

Issue 2702503002: Block renderer-initiated main frame navigations to data URLs (Closed)
Patch Set: Fix downloads, plugin handling and browser side navigations Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/frame_host/data_url_navigation_throttle.cc
diff --git a/content/browser/frame_host/data_url_navigation_throttle.cc b/content/browser/frame_host/data_url_navigation_throttle.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8ee094db08d1424b984fe753fa16f69e5e25fee7
--- /dev/null
+++ b/content/browser/frame_host/data_url_navigation_throttle.cc
@@ -0,0 +1,52 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/frame_host/data_url_navigation_throttle.h"
+
+#include "base/memory/ptr_util.h"
+#include "base/strings/stringprintf.h"
+#include "content/public/browser/navigation_handle.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/common/browser_side_navigation_policy.h"
+#include "content/public/common/console_message_level.h"
+#include "url/url_constants.h"
+
+namespace content {
+
+namespace {
+const char kConsoleError[] =
+ "Not allowed to top-level navigate to resource: %s";
+}
+
+DataUrlNavigationThrottle::DataUrlNavigationThrottle(
+ NavigationHandle* navigation_handle)
+ : NavigationThrottle(navigation_handle) {}
+
+DataUrlNavigationThrottle::~DataUrlNavigationThrottle() {}
+
+NavigationThrottle::ThrottleCheckResult
+DataUrlNavigationThrottle::WillProcessResponse() {
+ if (navigation_handle()->GetURL().SchemeIs(url::kDataScheme) &&
+ navigation_handle()->IsInMainFrame() &&
+ navigation_handle()->IsRendererInitiated() &&
+ !navigation_handle()->IsDownload()) {
+ navigation_handle()->GetRenderFrameHost()->AddMessageToConsole(
+ CONSOLE_MESSAGE_LEVEL_ERROR,
+ base::StringPrintf(kConsoleError,
+ navigation_handle()->GetURL().spec().c_str()));
+ return CANCEL;
+ }
+ return PROCEED;
+}
+
+// static
+std::unique_ptr<NavigationThrottle>
+DataUrlNavigationThrottle::CreateThrottleForNavigation(
+ NavigationHandle* navigation_handle) {
+ if (IsBrowserSideNavigationEnabled())
+ return base::WrapUnique(new DataUrlNavigationThrottle(navigation_handle));
+ return nullptr;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698