OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/frame_host/render_frame_proxy_host.h" | 5 #include "content/browser/frame_host/render_frame_proxy_host.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "content/browser/bad_message.h" | 10 #include "content/browser/bad_message.h" |
11 #include "content/browser/child_process_security_policy_impl.h" | |
11 #include "content/browser/frame_host/cross_process_frame_connector.h" | 12 #include "content/browser/frame_host/cross_process_frame_connector.h" |
12 #include "content/browser/frame_host/frame_tree.h" | 13 #include "content/browser/frame_host/frame_tree.h" |
13 #include "content/browser/frame_host/frame_tree_node.h" | 14 #include "content/browser/frame_host/frame_tree_node.h" |
14 #include "content/browser/frame_host/navigator.h" | 15 #include "content/browser/frame_host/navigator.h" |
15 #include "content/browser/frame_host/render_frame_host_delegate.h" | 16 #include "content/browser/frame_host/render_frame_host_delegate.h" |
16 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 17 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
17 #include "content/browser/renderer_host/render_view_host_impl.h" | 18 #include "content/browser/renderer_host/render_view_host_impl.h" |
18 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 19 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
19 #include "content/browser/site_instance_impl.h" | 20 #include "content/browser/site_instance_impl.h" |
20 #include "content/common/frame_messages.h" | 21 #include "content/common/frame_messages.h" |
21 #include "content/common/frame_owner_properties.h" | 22 #include "content/common/frame_owner_properties.h" |
23 #include "content/common/resource_request_body_impl.h" | |
24 #include "content/public/browser/browser_context.h" | |
22 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/browser/storage_partition.h" | |
23 #include "ipc/ipc_message.h" | 27 #include "ipc/ipc_message.h" |
28 #include "storage/browser/fileapi/file_system_context.h" | |
24 | 29 |
25 namespace content { | 30 namespace content { |
26 | 31 |
27 namespace { | 32 namespace { |
28 | 33 |
29 // The (process id, routing id) pair that identifies one RenderFrameProxy. | 34 // The (process id, routing id) pair that identifies one RenderFrameProxy. |
30 typedef std::pair<int32_t, int32_t> RenderFrameProxyHostID; | 35 typedef std::pair<int32_t, int32_t> RenderFrameProxyHostID; |
31 typedef base::hash_map<RenderFrameProxyHostID, RenderFrameProxyHost*> | 36 typedef base::hash_map<RenderFrameProxyHostID, RenderFrameProxyHost*> |
32 RoutingIDFrameProxyMap; | 37 RoutingIDFrameProxyMap; |
33 base::LazyInstance<RoutingIDFrameProxyMap>::DestructorAtExit | 38 base::LazyInstance<RoutingIDFrameProxyMap>::DestructorAtExit |
34 g_routing_id_frame_proxy_map = LAZY_INSTANCE_INITIALIZER; | 39 g_routing_id_frame_proxy_map = LAZY_INSTANCE_INITIALIZER; |
40 | |
41 // TODO(lukasza): https://crbug.com/726067: Remove code duplication - the | |
42 // function below should be reused by RenderFrameHostImpl::OnBeginNavigation and | |
43 // ResourceDispatcherHostImpl::ShouldServiceRequest. | |
Łukasz Anforowicz
2017/05/25 15:46:37
I've duplicated the code, so that this CL is (hope
| |
44 bool CanReadRequestBody(SiteInstance* site_instance, | |
45 const scoped_refptr<ResourceRequestBodyImpl>& body) { | |
46 if (!body) | |
47 return true; | |
48 | |
49 ChildProcessSecurityPolicyImpl* security_policy = | |
50 ChildProcessSecurityPolicyImpl::GetInstance(); | |
51 int child_id = site_instance->GetProcess()->GetID(); | |
52 | |
53 StoragePartition* storage_partition = BrowserContext::GetStoragePartition( | |
54 site_instance->GetBrowserContext(), site_instance); | |
55 const storage::FileSystemContext* file_system_context = | |
56 storage_partition->GetFileSystemContext(); | |
57 | |
58 for (const ResourceRequestBodyImpl::Element& element : *body->elements()) { | |
59 switch (element.type()) { | |
alexmos
2017/05/25 18:17:34
Thanks for being thorough and investigating all th
| |
60 case ResourceRequestBodyImpl::Element::TYPE_FILE: | |
61 if (!security_policy->CanReadFile(child_id, element.path())) | |
62 return false; | |
63 break; | |
64 | |
65 case ResourceRequestBodyImpl::Element::TYPE_FILE_FILESYSTEM: | |
66 if (!security_policy->CanReadFileSystemFile( | |
67 child_id, | |
68 file_system_context->CrackURL(element.filesystem_url()))) | |
69 return false; | |
70 break; | |
71 | |
72 case ResourceRequestBodyImpl::Element::TYPE_DISK_CACHE_ENTRY: | |
73 // TYPE_DISK_CACHE_ENTRY can't be sent via IPC according to | |
74 // content/common/resource_messages.cc | |
75 NOTREACHED(); | |
76 return false; | |
77 | |
78 case ResourceRequestBodyImpl::Element::TYPE_BYTES: | |
79 case ResourceRequestBodyImpl::Element::TYPE_BYTES_DESCRIPTION: | |
80 // Data is self-contained within |body| - no need to check access. | |
81 break; | |
82 | |
83 case ResourceRequestBodyImpl::Element::TYPE_BLOB: | |
84 // No need to validate - the unguessability of the uuid of the blob is a | |
85 // sufficient defense against access from an unrelated renderer. | |
86 break; | |
87 | |
88 case ResourceRequestBodyImpl::Element::TYPE_UNKNOWN: | |
89 default: | |
90 // Fail safe - deny access. | |
91 NOTREACHED(); | |
92 return false; | |
93 } | |
94 } | |
95 return true; | |
35 } | 96 } |
36 | 97 |
98 } // namespace | |
99 | |
37 // static | 100 // static |
38 RenderFrameProxyHost* RenderFrameProxyHost::FromID(int process_id, | 101 RenderFrameProxyHost* RenderFrameProxyHost::FromID(int process_id, |
39 int routing_id) { | 102 int routing_id) { |
40 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 103 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
41 RoutingIDFrameProxyMap* frames = g_routing_id_frame_proxy_map.Pointer(); | 104 RoutingIDFrameProxyMap* frames = g_routing_id_frame_proxy_map.Pointer(); |
42 RoutingIDFrameProxyMap::iterator it = frames->find( | 105 RoutingIDFrameProxyMap::iterator it = frames->find( |
43 RenderFrameProxyHostID(process_id, routing_id)); | 106 RenderFrameProxyHostID(process_id, routing_id)); |
44 return it == frames->end() ? NULL : it->second; | 107 return it == frames->end() ? NULL : it->second; |
45 } | 108 } |
46 | 109 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 const FrameHostMsg_OpenURL_Params& params) { | 306 const FrameHostMsg_OpenURL_Params& params) { |
244 GURL validated_url(params.url); | 307 GURL validated_url(params.url); |
245 GetProcess()->FilterURL(false, &validated_url); | 308 GetProcess()->FilterURL(false, &validated_url); |
246 | 309 |
247 // Verify that we are in the same BrowsingInstance as the current | 310 // Verify that we are in the same BrowsingInstance as the current |
248 // RenderFrameHost. | 311 // RenderFrameHost. |
249 RenderFrameHostImpl* current_rfh = frame_tree_node_->current_frame_host(); | 312 RenderFrameHostImpl* current_rfh = frame_tree_node_->current_frame_host(); |
250 if (!site_instance_->IsRelatedSiteInstance(current_rfh->GetSiteInstance())) | 313 if (!site_instance_->IsRelatedSiteInstance(current_rfh->GetSiteInstance())) |
251 return; | 314 return; |
252 | 315 |
316 // Verify if the request originator (*not* |current_rfh|) has access to the | |
317 // contents of the POST body. | |
318 if (!CanReadRequestBody(GetSiteInstance(), params.resource_request_body)) { | |
alexmos
2017/05/25 18:17:34
Sanity check: is the same check needed in RenderFr
Łukasz Anforowicz
2017/05/25 19:56:01
Thanks for catching this. Done.
| |
319 bad_message::ReceivedBadMessage(GetProcess(), | |
320 bad_message::RFPH_ILLEGAL_UPLOAD_PARAMS); | |
321 return; | |
322 } | |
323 | |
253 // Since this navigation targeted a specific RenderFrameProxy, it should stay | 324 // Since this navigation targeted a specific RenderFrameProxy, it should stay |
254 // in the current tab. | 325 // in the current tab. |
255 DCHECK_EQ(WindowOpenDisposition::CURRENT_TAB, params.disposition); | 326 DCHECK_EQ(WindowOpenDisposition::CURRENT_TAB, params.disposition); |
256 | 327 |
257 // TODO(alexmos, creis): Figure out whether |params.user_gesture| needs to be | 328 // TODO(alexmos, creis): Figure out whether |params.user_gesture| needs to be |
258 // passed in as well. | 329 // passed in as well. |
259 // TODO(lfg, lukasza): Remove |extra_headers| parameter from | 330 // TODO(lfg, lukasza): Remove |extra_headers| parameter from |
260 // RequestTransferURL method once both RenderFrameProxyHost and | 331 // RequestTransferURL method once both RenderFrameProxyHost and |
261 // RenderFrameHostImpl call RequestOpenURL from their OnOpenURL handlers. | 332 // RenderFrameHostImpl call RequestOpenURL from their OnOpenURL handlers. |
262 // See also https://crbug.com/647772. | 333 // See also https://crbug.com/647772. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 | 417 |
347 target_rfh->AdvanceFocus(type, source_proxy); | 418 target_rfh->AdvanceFocus(type, source_proxy); |
348 } | 419 } |
349 | 420 |
350 void RenderFrameProxyHost::OnFrameFocused() { | 421 void RenderFrameProxyHost::OnFrameFocused() { |
351 frame_tree_node_->current_frame_host()->delegate()->SetFocusedFrame( | 422 frame_tree_node_->current_frame_host()->delegate()->SetFocusedFrame( |
352 frame_tree_node_, GetSiteInstance()); | 423 frame_tree_node_, GetSiteInstance()); |
353 } | 424 } |
354 | 425 |
355 } // namespace content | 426 } // namespace content |
OLD | NEW |