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

Side by Side Diff: chrome/renderer/extensions/resource_request_policy.cc

Issue 1312653003: Fix for WebView accessible resources. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments by kalman@. Created 5 years, 3 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/renderer/extensions/resource_request_policy.h" 5 #include "chrome/renderer/extensions/resource_request_policy.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "chrome/common/extensions/chrome_manifest_url_handlers.h" 9 #include "chrome/common/extensions/chrome_manifest_url_handlers.h"
10 #include "chrome/common/url_constants.h" 10 #include "chrome/common/url_constants.h"
11 #include "extensions/common/constants.h" 11 #include "extensions/common/constants.h"
12 #include "extensions/common/extension.h" 12 #include "extensions/common/extension.h"
13 #include "extensions/common/manifest_constants.h"
13 #include "extensions/common/manifest_handlers/icons_handler.h" 14 #include "extensions/common/manifest_handlers/icons_handler.h"
14 #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" 15 #include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
16 #include "extensions/common/manifest_handlers/webview_info.h"
17 #include "extensions/renderer/dispatcher.h"
15 #include "extensions/renderer/renderer_extension_registry.h" 18 #include "extensions/renderer/renderer_extension_registry.h"
16 #include "third_party/WebKit/public/platform/WebString.h" 19 #include "third_party/WebKit/public/platform/WebString.h"
17 #include "third_party/WebKit/public/web/WebConsoleMessage.h" 20 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
18 #include "third_party/WebKit/public/web/WebDocument.h" 21 #include "third_party/WebKit/public/web/WebDocument.h"
19 #include "third_party/WebKit/public/web/WebFrame.h" 22 #include "third_party/WebKit/public/web/WebFrame.h"
20 #include "ui/base/page_transition_types.h" 23 #include "ui/base/page_transition_types.h"
21 #include "url/gurl.h" 24 #include "url/gurl.h"
22 25
23 namespace extensions { 26 namespace extensions {
24 27
28 ResourceRequestPolicy::ResourceRequestPolicy(Dispatcher* dispatcher)
29 : dispatcher_(dispatcher) {}
30
25 // This method does a security check whether chrome-extension:// URLs can be 31 // This method does a security check whether chrome-extension:// URLs can be
26 // requested by the renderer. Since this is in an untrusted process, the browser 32 // requested by the renderer. Since this is in an untrusted process, the browser
27 // has a similar check to enforce the policy, in case this process is exploited. 33 // has a similar check to enforce the policy, in case this process is exploited.
28 // If you are changing this function, ensure equivalent checks are added to 34 // If you are changing this function, ensure equivalent checks are added to
29 // extension_protocols.cc's AllowExtensionResourceLoad. 35 // extension_protocols.cc's AllowExtensionResourceLoad.
30
31 // static
32 bool ResourceRequestPolicy::CanRequestResource( 36 bool ResourceRequestPolicy::CanRequestResource(
33 const GURL& resource_url, 37 const GURL& resource_url,
34 blink::WebFrame* frame, 38 blink::WebFrame* frame,
35 ui::PageTransition transition_type) { 39 ui::PageTransition transition_type) {
36 CHECK(resource_url.SchemeIs(extensions::kExtensionScheme)); 40 CHECK(resource_url.SchemeIs(kExtensionScheme));
37 41
38 const Extension* extension = 42 const Extension* extension =
39 RendererExtensionRegistry::Get()->GetExtensionOrAppByURL(resource_url); 43 RendererExtensionRegistry::Get()->GetExtensionOrAppByURL(resource_url);
40 if (!extension) { 44 if (!extension) {
41 // Allow the load in the case of a non-existent extension. We'll just get a 45 // Allow the load in the case of a non-existent extension. We'll just get a
42 // 404 from the browser process. 46 // 404 from the browser process.
43 return true; 47 return true;
44 } 48 }
45 49
46 // Disallow loading of packaged resources for hosted apps. We don't allow 50 // Disallow loading of packaged resources for hosted apps. We don't allow
47 // hybrid hosted/packaged apps. The one exception is access to icons, since 51 // hybrid hosted/packaged apps. The one exception is access to icons, since
48 // some extensions want to be able to do things like create their own 52 // some extensions want to be able to do things like create their own
49 // launchers. 53 // launchers.
50 std::string resource_root_relative_path = 54 std::string resource_root_relative_path =
51 resource_url.path().empty() ? std::string() 55 resource_url.path().empty() ? std::string()
52 : resource_url.path().substr(1); 56 : resource_url.path().substr(1);
53 if (extension->is_hosted_app() && 57 if (extension->is_hosted_app() &&
54 !IconsInfo::GetIcons(extension) 58 !IconsInfo::GetIcons(extension)
55 .ContainsPath(resource_root_relative_path)) { 59 .ContainsPath(resource_root_relative_path)) {
56 LOG(ERROR) << "Denying load of " << resource_url.spec() << " from " 60 LOG(ERROR) << "Denying load of " << resource_url.spec() << " from "
57 << "hosted app."; 61 << "hosted app.";
58 return false; 62 return false;
59 } 63 }
60 64
61 // Disallow loading of extension resources which are not explicitly listed 65 // Disallow loading of extension resources which are not explicitly listed
62 // as web accessible if the manifest version is 2 or greater. 66 // as web or WebView accessible if the manifest version is 2 or greater.
67 const WebviewInfo* webview_info = WebviewInfo::Get(extension);
63 if (!WebAccessibleResourcesInfo::IsResourceWebAccessible( 68 if (!WebAccessibleResourcesInfo::IsResourceWebAccessible(
64 extension, resource_url.path())) { 69 extension, resource_url.path()) &&
70 !(webview_info &&
71 webview_info->IsResourceWebviewAccessible(
not at google - send to devlin 2015/09/03 20:17:54 See point about WebviewInfo::IsResourceWebviewAcce
paulmeyer 2015/09/08 18:51:36 Done.
72 extension, dispatcher_->webview_partition_id(),
73 resource_url.path()))) {
65 GURL frame_url = frame->document().url(); 74 GURL frame_url = frame->document().url();
66 75
67 // The page_origin may be GURL("null") for unique origins like data URLs, 76 // The page_origin may be GURL("null") for unique origins like data URLs,
68 // but this is ok for the checks below. We only care if it matches the 77 // but this is ok for the checks below. We only care if it matches the
69 // current extension or has a devtools scheme. 78 // current extension or has a devtools scheme.
70 GURL page_origin = GURL(frame->top()->securityOrigin().toString()); 79 GURL page_origin = GURL(frame->top()->securityOrigin().toString());
71 80
72 // Exceptions are: 81 // Exceptions are:
73 // - empty origin (needed for some edge cases when we have empty origins) 82 // - empty origin (needed for some edge cases when we have empty origins)
74 bool is_empty_origin = frame_url.is_empty(); 83 bool is_empty_origin = frame_url.is_empty();
(...skipping 22 matching lines...) Expand all
97 frame->addMessageToConsole( 106 frame->addMessageToConsole(
98 blink::WebConsoleMessage(blink::WebConsoleMessage::LevelError, 107 blink::WebConsoleMessage(blink::WebConsoleMessage::LevelError,
99 blink::WebString::fromUTF8(message))); 108 blink::WebString::fromUTF8(message)));
100 return false; 109 return false;
101 } 110 }
102 } 111 }
103 112
104 return true; 113 return true;
105 } 114 }
106 115
107 // static
108 bool ResourceRequestPolicy::CanRequestExtensionResourceScheme( 116 bool ResourceRequestPolicy::CanRequestExtensionResourceScheme(
109 const GURL& resource_url, 117 const GURL& resource_url,
110 blink::WebFrame* frame) { 118 blink::WebFrame* frame) {
111 CHECK(resource_url.SchemeIs(extensions::kExtensionResourceScheme)); 119 CHECK(resource_url.SchemeIs(kExtensionResourceScheme));
112 120
113 GURL frame_url = frame->document().url(); 121 GURL frame_url = frame->document().url();
114 if (!frame_url.is_empty() && 122 if (!frame_url.is_empty() && !frame_url.SchemeIs(kExtensionScheme)) {
115 !frame_url.SchemeIs(extensions::kExtensionScheme)) {
116 std::string message = base::StringPrintf( 123 std::string message = base::StringPrintf(
117 "Denying load of %s. chrome-extension-resources:// can only be " 124 "Denying load of %s. chrome-extension-resources:// can only be "
118 "loaded from extensions.", 125 "loaded from extensions.",
119 resource_url.spec().c_str()); 126 resource_url.spec().c_str());
120 frame->addMessageToConsole( 127 frame->addMessageToConsole(
121 blink::WebConsoleMessage(blink::WebConsoleMessage::LevelError, 128 blink::WebConsoleMessage(blink::WebConsoleMessage::LevelError,
122 blink::WebString::fromUTF8(message))); 129 blink::WebString::fromUTF8(message)));
123 return false; 130 return false;
124 } 131 }
125 132
126 return true; 133 return true;
127 } 134 }
128 135
129 ResourceRequestPolicy::ResourceRequestPolicy() {
130 }
131
132 } // namespace extensions 136 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698