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

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

Issue 2067493003: Moving (Can|Grant)AccessFilesOfPageState into RenderFrameHostImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@grant-file-access-after-transfer
Patch Set: Rebasing... Created 4 years, 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_host_impl.h" 5 #include "content/browser/frame_host/render_frame_host_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/containers/hash_tables.h" 11 #include "base/containers/hash_tables.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/process/kill.h" 15 #include "base/process/kill.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "content/browser/accessibility/accessibility_mode_helper.h" 18 #include "content/browser/accessibility/accessibility_mode_helper.h"
19 #include "content/browser/accessibility/ax_tree_id_registry.h" 19 #include "content/browser/accessibility/ax_tree_id_registry.h"
20 #include "content/browser/accessibility/browser_accessibility_manager.h" 20 #include "content/browser/accessibility/browser_accessibility_manager.h"
21 #include "content/browser/accessibility/browser_accessibility_state_impl.h" 21 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
22 #include "content/browser/bluetooth/web_bluetooth_service_impl.h" 22 #include "content/browser/bluetooth/web_bluetooth_service_impl.h"
23 #include "content/browser/child_process_security_policy_impl.h" 23 #include "content/browser/child_process_security_policy_impl.h"
24 #include "content/browser/child_process_security_policy_impl.h"
25 #include "content/browser/devtools/render_frame_devtools_agent_host.h" 24 #include "content/browser/devtools/render_frame_devtools_agent_host.h"
26 #include "content/browser/download/mhtml_generation_manager.h" 25 #include "content/browser/download/mhtml_generation_manager.h"
27 #include "content/browser/frame_host/cross_process_frame_connector.h" 26 #include "content/browser/frame_host/cross_process_frame_connector.h"
28 #include "content/browser/frame_host/cross_site_transferring_request.h" 27 #include "content/browser/frame_host/cross_site_transferring_request.h"
29 #include "content/browser/frame_host/frame_mojo_shell.h" 28 #include "content/browser/frame_host/frame_mojo_shell.h"
30 #include "content/browser/frame_host/frame_tree.h" 29 #include "content/browser/frame_host/frame_tree.h"
31 #include "content/browser/frame_host/frame_tree_node.h" 30 #include "content/browser/frame_host/frame_tree_node.h"
32 #include "content/browser/frame_host/navigation_entry_impl.h" 31 #include "content/browser/frame_host/navigation_entry_impl.h"
33 #include "content/browser/frame_host/navigation_handle_impl.h" 32 #include "content/browser/frame_host/navigation_handle_impl.h"
34 #include "content/browser/frame_host/navigation_request.h" 33 #include "content/browser/frame_host/navigation_request.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 153 }
155 } 154 }
156 155
157 void disable() { disabled_ = true; } 156 void disable() { disabled_ = true; }
158 157
159 private: 158 private:
160 RenderFrameHostImpl* render_frame_host_; 159 RenderFrameHostImpl* render_frame_host_;
161 bool disabled_; 160 bool disabled_;
162 }; 161 };
163 162
163 void GrantFileAccess(int child_id,
164 const std::vector<base::FilePath>& file_paths) {
165 ChildProcessSecurityPolicyImpl* policy =
166 ChildProcessSecurityPolicyImpl::GetInstance();
167
168 for (const auto& file : file_paths) {
169 if (!policy->CanReadFile(child_id, file))
170 policy->GrantReadFile(child_id, file);
171 }
172 }
173
164 } // namespace 174 } // namespace
165 175
166 // static 176 // static
167 RenderFrameHost* RenderFrameHost::FromID(int render_process_id, 177 RenderFrameHost* RenderFrameHost::FromID(int render_process_id,
168 int render_frame_id) { 178 int render_frame_id) {
169 return RenderFrameHostImpl::FromID(render_process_id, render_frame_id); 179 return RenderFrameHostImpl::FromID(render_process_id, render_frame_id);
170 } 180 }
171 181
172 #if defined(OS_ANDROID) 182 #if defined(OS_ANDROID)
173 // static 183 // static
(...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 process->FilterURL(false, &validated_params.url); 1088 process->FilterURL(false, &validated_params.url);
1079 process->FilterURL(true, &validated_params.referrer.url); 1089 process->FilterURL(true, &validated_params.referrer.url);
1080 for (std::vector<GURL>::iterator it(validated_params.redirects.begin()); 1090 for (std::vector<GURL>::iterator it(validated_params.redirects.begin());
1081 it != validated_params.redirects.end(); ++it) { 1091 it != validated_params.redirects.end(); ++it) {
1082 process->FilterURL(false, &(*it)); 1092 process->FilterURL(false, &(*it));
1083 } 1093 }
1084 process->FilterURL(true, &validated_params.searchable_form_url); 1094 process->FilterURL(true, &validated_params.searchable_form_url);
1085 1095
1086 // Without this check, the renderer can trick the browser into using 1096 // Without this check, the renderer can trick the browser into using
1087 // filenames it can't access in a future session restore. 1097 // filenames it can't access in a future session restore.
1088 if (!render_view_host_->CanAccessFilesOfPageState( 1098 if (!CanAccessFilesOfPageState(validated_params.page_state)) {
1089 validated_params.page_state)) {
1090 bad_message::ReceivedBadMessage( 1099 bad_message::ReceivedBadMessage(
1091 GetProcess(), bad_message::RFH_CAN_ACCESS_FILES_OF_PAGE_STATE); 1100 GetProcess(), bad_message::RFH_CAN_ACCESS_FILES_OF_PAGE_STATE);
1092 return; 1101 return;
1093 } 1102 }
1094 1103
1095 // If the URL does not match what the NavigationHandle expects, treat the 1104 // If the URL does not match what the NavigationHandle expects, treat the
1096 // commit as a new navigation. This can happen if an ongoing slow 1105 // commit as a new navigation. This can happen if an ongoing slow
1097 // same-process navigation is interrupted by a synchronous renderer-initiated 1106 // same-process navigation is interrupted by a synchronous renderer-initiated
1098 // navigation. 1107 // navigation.
1099 // TODO(csharrison): Data navigations loaded with LoadDataWithBaseURL get 1108 // TODO(csharrison): Data navigations loaded with LoadDataWithBaseURL get
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 RenderWidgetHostImpl::From(GetView()->GetRenderWidgetHost()) 1179 RenderWidgetHostImpl::From(GetView()->GetRenderWidgetHost())
1171 ->StartNewContentRenderingTimeout(); 1180 ->StartNewContentRenderingTimeout();
1172 } 1181 }
1173 } 1182 }
1174 1183
1175 void RenderFrameHostImpl::OnUpdateState(const PageState& state) { 1184 void RenderFrameHostImpl::OnUpdateState(const PageState& state) {
1176 // TODO(creis): Verify the state's ISN matches the last committed FNE. 1185 // TODO(creis): Verify the state's ISN matches the last committed FNE.
1177 1186
1178 // Without this check, the renderer can trick the browser into using 1187 // Without this check, the renderer can trick the browser into using
1179 // filenames it can't access in a future session restore. 1188 // filenames it can't access in a future session restore.
1180 // TODO(creis): Move CanAccessFilesOfPageState to RenderFrameHostImpl. 1189 if (!CanAccessFilesOfPageState(state)) {
1181 if (!render_view_host_->CanAccessFilesOfPageState(state)) {
1182 bad_message::ReceivedBadMessage( 1190 bad_message::ReceivedBadMessage(
1183 GetProcess(), bad_message::RFH_CAN_ACCESS_FILES_OF_PAGE_STATE); 1191 GetProcess(), bad_message::RFH_CAN_ACCESS_FILES_OF_PAGE_STATE);
1184 return; 1192 return;
1185 } 1193 }
1186 1194
1187 delegate_->UpdateStateForFrame(this, state); 1195 delegate_->UpdateStateForFrame(this, state);
1188 } 1196 }
1189 1197
1190 RenderWidgetHostImpl* RenderFrameHostImpl::GetRenderWidgetHost() { 1198 RenderWidgetHostImpl* RenderFrameHostImpl::GetRenderWidgetHost() {
1191 RenderFrameHostImpl* frame = this; 1199 RenderFrameHostImpl* frame = this;
(...skipping 1558 matching lines...) Expand 10 before | Expand all | Expand 10 after
2750 if (!permission_manager) 2758 if (!permission_manager)
2751 return; 2759 return;
2752 2760
2753 permission_manager->RegisterPermissionUsage( 2761 permission_manager->RegisterPermissionUsage(
2754 PermissionType::GEOLOCATION, 2762 PermissionType::GEOLOCATION,
2755 last_committed_url().GetOrigin(), 2763 last_committed_url().GetOrigin(),
2756 frame_tree_node()->frame_tree()->GetMainFrame() 2764 frame_tree_node()->frame_tree()->GetMainFrame()
2757 ->last_committed_url().GetOrigin()); 2765 ->last_committed_url().GetOrigin());
2758 } 2766 }
2759 2767
2768 bool RenderFrameHostImpl::CanAccessFilesOfPageState(const PageState& state) {
2769 return ChildProcessSecurityPolicyImpl::GetInstance()->CanReadAllFiles(
2770 GetProcess()->GetID(), state.GetReferencedFiles());
2771 }
2772
2773 void RenderFrameHostImpl::GrantFileAccessFromPageState(const PageState& state) {
2774 GrantFileAccess(GetProcess()->GetID(), state.GetReferencedFiles());
2775 }
2776
2760 void RenderFrameHostImpl::GrantFileAccessFromResourceRequestBody( 2777 void RenderFrameHostImpl::GrantFileAccessFromResourceRequestBody(
2761 const ResourceRequestBodyImpl& body) { 2778 const ResourceRequestBodyImpl& body) {
2762 ChildProcessSecurityPolicyImpl* policy = 2779 GrantFileAccess(GetProcess()->GetID(), body.GetReferencedFiles());
2763 ChildProcessSecurityPolicyImpl::GetInstance();
2764
2765 std::vector<base::FilePath> file_paths = body.GetReferencedFiles();
2766 for (const auto& file : file_paths) {
2767 if (!policy->CanReadFile(GetProcess()->GetID(), file))
2768 policy->GrantReadFile(GetProcess()->GetID(), file);
2769 }
2770 } 2780 }
2771 2781
2772 void RenderFrameHostImpl::UpdatePermissionsForNavigation( 2782 void RenderFrameHostImpl::UpdatePermissionsForNavigation(
2773 const CommonNavigationParams& common_params, 2783 const CommonNavigationParams& common_params,
2774 const RequestNavigationParams& request_params) { 2784 const RequestNavigationParams& request_params) {
2775 // Browser plugin guests are not allowed to navigate outside web-safe schemes, 2785 // Browser plugin guests are not allowed to navigate outside web-safe schemes,
2776 // so do not grant them the ability to request additional URLs. 2786 // so do not grant them the ability to request additional URLs.
2777 if (!GetProcess()->IsForGuestsOnly()) { 2787 if (!GetProcess()->IsForGuestsOnly()) {
2778 ChildProcessSecurityPolicyImpl::GetInstance()->GrantRequestURL( 2788 ChildProcessSecurityPolicyImpl::GetInstance()->GrantRequestURL(
2779 GetProcess()->GetID(), common_params.url); 2789 GetProcess()->GetID(), common_params.url);
2780 if (common_params.url.SchemeIs(url::kDataScheme) && 2790 if (common_params.url.SchemeIs(url::kDataScheme) &&
2781 common_params.base_url_for_data_url.SchemeIs(url::kFileScheme)) { 2791 common_params.base_url_for_data_url.SchemeIs(url::kFileScheme)) {
2782 // If 'data:' is used, and we have a 'file:' base url, grant access to 2792 // If 'data:' is used, and we have a 'file:' base url, grant access to
2783 // local files. 2793 // local files.
2784 ChildProcessSecurityPolicyImpl::GetInstance()->GrantRequestURL( 2794 ChildProcessSecurityPolicyImpl::GetInstance()->GrantRequestURL(
2785 GetProcess()->GetID(), common_params.base_url_for_data_url); 2795 GetProcess()->GetID(), common_params.base_url_for_data_url);
2786 } 2796 }
2787 } 2797 }
2788 2798
2789 // We may be returning to an existing NavigationEntry that had been granted 2799 // We may be returning to an existing NavigationEntry that had been granted
2790 // file access. If this is a different process, we will need to grant the 2800 // file access. If this is a different process, we will need to grant the
2791 // access again. Abuse is prevented, because the files listed in the page 2801 // access again. Abuse is prevented, because the files listed in the page
2792 // state are validated earlier, when they are received from the renderer (in 2802 // state are validated earlier, when they are received from the renderer (in
2793 // RenderFrameHostImpl::CanAccessFilesOfPageState). 2803 // RenderFrameHostImpl::CanAccessFilesOfPageState).
2794 if (request_params.page_state.IsValid()) 2804 if (request_params.page_state.IsValid())
2795 render_view_host_->GrantFileAccessFromPageState(request_params.page_state); 2805 GrantFileAccessFromPageState(request_params.page_state);
2796 2806
2797 // We may be here after transferring navigation to a different renderer 2807 // We may be here after transferring navigation to a different renderer
2798 // process. In this case, we need to ensure that the new renderer retains 2808 // process. In this case, we need to ensure that the new renderer retains
2799 // ability to access files that the old renderer could access. Abuse is 2809 // ability to access files that the old renderer could access. Abuse is
2800 // prevented, because the files listed in ResourceRequestBody are validated 2810 // prevented, because the files listed in ResourceRequestBody are validated
2801 // earlier, when they are recieved from the renderer (in ShouldServiceRequest 2811 // earlier, when they are recieved from the renderer (in ShouldServiceRequest
2802 // called from ResourceDispatcherHostImpl::BeginRequest). 2812 // called from ResourceDispatcherHostImpl::BeginRequest).
2803 if (common_params.post_data) 2813 if (common_params.post_data)
2804 GrantFileAccessFromResourceRequestBody(*common_params.post_data); 2814 GrantFileAccessFromResourceRequestBody(*common_params.post_data);
2805 } 2815 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
2927 // handler after it's destroyed so it can't run after the RFHI is destroyed. 2937 // handler after it's destroyed so it can't run after the RFHI is destroyed.
2928 web_bluetooth_service_->SetClientConnectionErrorHandler(base::Bind( 2938 web_bluetooth_service_->SetClientConnectionErrorHandler(base::Bind(
2929 &RenderFrameHostImpl::DeleteWebBluetoothService, base::Unretained(this))); 2939 &RenderFrameHostImpl::DeleteWebBluetoothService, base::Unretained(this)));
2930 } 2940 }
2931 2941
2932 void RenderFrameHostImpl::DeleteWebBluetoothService() { 2942 void RenderFrameHostImpl::DeleteWebBluetoothService() {
2933 web_bluetooth_service_.reset(); 2943 web_bluetooth_service_.reset();
2934 } 2944 }
2935 2945
2936 } // namespace content 2946 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_impl.h ('k') | content/browser/renderer_host/render_view_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698