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

Side by Side Diff: content/browser/frame_host/data_url_navigation_throttle.cc

Issue 2702503002: Block renderer-initiated main frame navigations to data URLs (Closed)
Patch Set: Cleanup 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/frame_host/data_url_navigation_throttle.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "base/strings/stringprintf.h"
9 #include "content/public/browser/navigation_handle.h"
10 #include "content/public/browser/render_frame_host.h"
11 #include "content/public/common/console_message_level.h"
12 #include "url/url_constants.h"
13
14 namespace content {
15
16 namespace {
17 const char kConsoleError[] =
18 "Not allowed to top-level navigate to resource: %s";
19 }
20
21 DataUrlNavigationThrottle::DataUrlNavigationThrottle(
22 NavigationHandle* navigation_handle)
23 : NavigationThrottle(navigation_handle) {}
24
25 DataUrlNavigationThrottle::~DataUrlNavigationThrottle() {}
26
27 NavigationThrottle::ThrottleCheckResult
28 DataUrlNavigationThrottle::WillProcessResponse() {
29 if (navigation_handle()->GetURL().SchemeIs(url::kDataScheme) &&
30 navigation_handle()->IsInMainFrame() &&
31 navigation_handle()->IsRendererInitiated() &&
32 !navigation_handle()->IsDownload()) {
33 navigation_handle()->GetRenderFrameHost()->AddMessageToConsole(
34 CONSOLE_MESSAGE_LEVEL_ERROR,
35 base::StringPrintf(kConsoleError,
36 navigation_handle()->GetURL().spec().c_str()));
nasko 2017/03/28 19:58:01 This code might also block navigations to data: UR
meacer 2017/03/28 20:44:35 I've been looking at this in the last few days. IM
37 return CANCEL;
38 }
39 return PROCEED;
40 }
41
42 // static
43 std::unique_ptr<NavigationThrottle>
44 DataUrlNavigationThrottle::CreateThrottleForNavigation(
45 NavigationHandle* navigation_handle) {
46 return base::WrapUnique(new DataUrlNavigationThrottle(navigation_handle));
nasko 2017/03/28 19:58:01 Does it make sense to install this throttle on all
meacer 2017/03/30 20:43:55 Changed it to install only if the data URL is pote
47 }
48
49 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698