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

Side by Side Diff: extensions/browser/extension_navigation_throttle.cc

Issue 2875493002: Block navigations to hosted apps non-icon resources with PlzNavigate. (Closed)
Patch Set: Add a test for allowed navigation to an icon file. Created 3 years, 7 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
« no previous file with comments | « chrome/test/data/extensions/hosted_app/manifest.json ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/browser/extension_navigation_throttle.h" 5 #include "extensions/browser/extension_navigation_throttle.h"
6 6
7 #include "components/guest_view/browser/guest_view_base.h" 7 #include "components/guest_view/browser/guest_view_base.h"
8 #include "content/public/browser/browser_thread.h" 8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/browser/navigation_handle.h" 9 #include "content/public/browser/navigation_handle.h"
10 #include "content/public/browser/render_frame_host.h" 10 #include "content/public/browser/render_frame_host.h"
11 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
12 #include "content/public/common/browser_side_navigation_policy.h" 12 #include "content/public/common/browser_side_navigation_policy.h"
13 #include "content/public/common/url_constants.h" 13 #include "content/public/common/url_constants.h"
14 #include "extensions/browser/extension_registry.h" 14 #include "extensions/browser/extension_registry.h"
15 #include "extensions/browser/guest_view/web_view/web_view_guest.h" 15 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
16 #include "extensions/browser/url_request_util.h" 16 #include "extensions/browser/url_request_util.h"
17 #include "extensions/common/constants.h" 17 #include "extensions/common/constants.h"
18 #include "extensions/common/extension.h" 18 #include "extensions/common/extension.h"
19 #include "extensions/common/extension_set.h" 19 #include "extensions/common/extension_set.h"
20 #include "extensions/common/manifest_handlers/icons_handler.h"
20 #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" 21 #include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
21 #include "extensions/common/manifest_handlers/webview_info.h" 22 #include "extensions/common/manifest_handlers/webview_info.h"
22 #include "extensions/common/permissions/api_permission.h" 23 #include "extensions/common/permissions/api_permission.h"
23 #include "extensions/common/permissions/permissions_data.h" 24 #include "extensions/common/permissions/permissions_data.h"
24 #include "ui/base/page_transition_types.h" 25 #include "ui/base/page_transition_types.h"
25 26
26 namespace extensions { 27 namespace extensions {
27 28
28 ExtensionNavigationThrottle::ExtensionNavigationThrottle( 29 ExtensionNavigationThrottle::ExtensionNavigationThrottle(
29 content::NavigationHandle* navigation_handle) 30 content::NavigationHandle* navigation_handle)
(...skipping 28 matching lines...) Expand all
58 return content::NavigationThrottle::PROCEED; 59 return content::NavigationThrottle::PROCEED;
59 } 60 }
60 61
61 // If the navigation is to an unknown or disabled extension, block it. 62 // If the navigation is to an unknown or disabled extension, block it.
62 if (!target_extension) { 63 if (!target_extension) {
63 // TODO(nick): This yields an unsatisfying error page; use a different error 64 // TODO(nick): This yields an unsatisfying error page; use a different error
64 // code once that's supported. https://crbug.com/649869 65 // code once that's supported. https://crbug.com/649869
65 return content::NavigationThrottle::BLOCK_REQUEST; 66 return content::NavigationThrottle::BLOCK_REQUEST;
66 } 67 }
67 68
69 // Hosted apps don't have any associated resources outside of icons, so
70 // block any requests to URLs in their extension origin.
71 // TODO(nasko): An equivalent check is performed in the renderer process
72 // inside ResourceRequestPolicy::CanRequestResource. It can be removed
73 // once PlzNavigate is the default.
ncarter (slow) 2017/05/24 21:13:16 Can we though? If you remove the enforcement in Re
nasko 2017/05/24 21:15:43 This is a good point. It might still be possible,
74 if (target_extension->is_hosted_app()) {
75 base::StringPiece resource_root_relative_path =
76 url.path_piece().empty() ? base::StringPiece()
77 : url.path_piece().substr(1);
78 if (!IconsInfo::GetIcons(target_extension)
79 .ContainsPath(resource_root_relative_path)) {
80 return content::NavigationThrottle::BLOCK_REQUEST;
81 }
82 }
83
68 if (navigation_handle()->IsInMainFrame()) { 84 if (navigation_handle()->IsInMainFrame()) {
69 // Block top-level navigations to blob: or filesystem: URLs with extension 85 // Block top-level navigations to blob: or filesystem: URLs with extension
70 // origin from non-extension processes. See https://crbug.com/645028. 86 // origin from non-extension processes. See https://crbug.com/645028.
71 bool current_frame_is_extension_process = 87 bool current_frame_is_extension_process =
72 !!registry->enabled_extensions().GetExtensionOrAppByURL( 88 !!registry->enabled_extensions().GetExtensionOrAppByURL(
73 navigation_handle()->GetStartingSiteInstance()->GetSiteURL()); 89 navigation_handle()->GetStartingSiteInstance()->GetSiteURL());
74 90
75 if (!url_has_extension_scheme && !current_frame_is_extension_process) { 91 if (!url_has_extension_scheme && !current_frame_is_extension_process) {
76 // Relax this restriction for apps that use <webview>. See 92 // Relax this restriction for apps that use <webview>. See
77 // https://crbug.com/652077. 93 // https://crbug.com/652077.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 return CANCEL; 183 return CANCEL;
168 } 184 }
169 return result; 185 return result;
170 } 186 }
171 187
172 const char* ExtensionNavigationThrottle::GetNameForLogging() { 188 const char* ExtensionNavigationThrottle::GetNameForLogging() {
173 return "ExtensionNavigationThrottle"; 189 return "ExtensionNavigationThrottle";
174 } 190 }
175 191
176 } // namespace extensions 192 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/hosted_app/manifest.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698