Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading | 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading |
| 6 | 6 |
| 7 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 7 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 request->set_referrer_policy(net_referrer_policy); | 268 request->set_referrer_policy(net_referrer_policy); |
| 269 } | 269 } |
| 270 | 270 |
| 271 // Consults the RendererSecurity policy to determine whether the | 271 // Consults the RendererSecurity policy to determine whether the |
| 272 // ResourceDispatcherHostImpl should service this request. A request might be | 272 // ResourceDispatcherHostImpl should service this request. A request might be |
| 273 // disallowed if the renderer is not authorized to retrieve the request URL or | 273 // disallowed if the renderer is not authorized to retrieve the request URL or |
| 274 // if the renderer is attempting to upload an unauthorized file. | 274 // if the renderer is attempting to upload an unauthorized file. |
| 275 bool ShouldServiceRequest(int process_type, | 275 bool ShouldServiceRequest(int process_type, |
| 276 int child_id, | 276 int child_id, |
| 277 const ResourceHostMsg_Request& request_data, | 277 const ResourceHostMsg_Request& request_data, |
| 278 storage::FileSystemContext* file_system_context) { | 278 const net::HttpRequestHeaders& headers, |
| 279 ResourceMessageFilter* filter, | |
| 280 ResourceContext* resource_context) { | |
| 279 if (process_type == PROCESS_TYPE_PLUGIN) | 281 if (process_type == PROCESS_TYPE_PLUGIN) |
| 280 return true; | 282 return true; |
| 281 | 283 |
| 282 ChildProcessSecurityPolicyImpl* policy = | 284 ChildProcessSecurityPolicyImpl* policy = |
| 283 ChildProcessSecurityPolicyImpl::GetInstance(); | 285 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 284 | 286 |
| 285 // Check if the renderer is permitted to request the requested URL. | 287 // Check if the renderer is permitted to request the requested URL. |
| 286 if (!policy->CanRequestURL(child_id, request_data.url)) { | 288 if (!policy->CanRequestURL(child_id, request_data.url)) { |
| 287 VLOG(1) << "Denied unauthorized request for " | 289 VLOG(1) << "Denied unauthorized request for " |
| 288 << request_data.url.possibly_invalid_spec(); | 290 << request_data.url.possibly_invalid_spec(); |
| 289 return false; | 291 return false; |
| 290 } | 292 } |
| 291 | 293 |
| 294 // Check if the renderer is using an illegal Origin header. If so, kill it. | |
| 295 std::string origin_string; | |
| 296 bool has_origin = headers.GetHeader("Origin", &origin_string) && | |
| 297 origin_string != "null"; | |
| 298 if (has_origin) { | |
| 299 GURL origin(origin_string); | |
| 300 if (!policy->CanCommitURL(child_id, origin) || | |
| 301 GetContentClient()->browser()->IsIllegalOrigin(resource_context, | |
| 302 child_id, origin)) { | |
| 303 VLOG(1) << "Killed renderer for illegal origin: " << origin_string; | |
| 304 bad_message::ReceivedBadMessage(filter, bad_message::RDH_INVALID_ORIGIN); | |
|
nasko
2015/08/14 22:14:43
nit: It will be good to be consistent in illegal v
Charlie Reis
2015/08/14 23:23:32
Done. (I was trying to be consistent with other c
| |
| 305 return false; | |
| 306 } | |
| 307 } | |
| 308 | |
| 292 // Check if the renderer is permitted to upload the requested files. | 309 // Check if the renderer is permitted to upload the requested files. |
| 293 if (request_data.request_body.get()) { | 310 if (request_data.request_body.get()) { |
| 294 const std::vector<ResourceRequestBody::Element>* uploads = | 311 const std::vector<ResourceRequestBody::Element>* uploads = |
| 295 request_data.request_body->elements(); | 312 request_data.request_body->elements(); |
| 296 std::vector<ResourceRequestBody::Element>::const_iterator iter; | 313 std::vector<ResourceRequestBody::Element>::const_iterator iter; |
| 297 for (iter = uploads->begin(); iter != uploads->end(); ++iter) { | 314 for (iter = uploads->begin(); iter != uploads->end(); ++iter) { |
| 298 if (iter->type() == ResourceRequestBody::Element::TYPE_FILE && | 315 if (iter->type() == ResourceRequestBody::Element::TYPE_FILE && |
| 299 !policy->CanReadFile(child_id, iter->path())) { | 316 !policy->CanReadFile(child_id, iter->path())) { |
| 300 NOTREACHED() << "Denied unauthorized upload of " | 317 NOTREACHED() << "Denied unauthorized upload of " |
| 301 << iter->path().value(); | 318 << iter->path().value(); |
| 302 return false; | 319 return false; |
| 303 } | 320 } |
| 304 if (iter->type() == ResourceRequestBody::Element::TYPE_FILE_FILESYSTEM) { | 321 if (iter->type() == ResourceRequestBody::Element::TYPE_FILE_FILESYSTEM) { |
| 305 storage::FileSystemURL url = | 322 storage::FileSystemURL url = |
| 306 file_system_context->CrackURL(iter->filesystem_url()); | 323 filter->file_system_context()->CrackURL(iter->filesystem_url()); |
| 307 if (!policy->CanReadFileSystemFile(child_id, url)) { | 324 if (!policy->CanReadFileSystemFile(child_id, url)) { |
| 308 NOTREACHED() << "Denied unauthorized upload of " | 325 NOTREACHED() << "Denied unauthorized upload of " |
| 309 << iter->filesystem_url().spec(); | 326 << iter->filesystem_url().spec(); |
| 310 return false; | 327 return false; |
| 311 } | 328 } |
| 312 } | 329 } |
| 313 } | 330 } |
| 314 } | 331 } |
| 315 | 332 |
| 316 return true; | 333 return true; |
| (...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1165 } | 1182 } |
| 1166 return; | 1183 return; |
| 1167 } | 1184 } |
| 1168 | 1185 |
| 1169 ResourceContext* resource_context = NULL; | 1186 ResourceContext* resource_context = NULL; |
| 1170 net::URLRequestContext* request_context = NULL; | 1187 net::URLRequestContext* request_context = NULL; |
| 1171 filter_->GetContexts(request_data, &resource_context, &request_context); | 1188 filter_->GetContexts(request_data, &resource_context, &request_context); |
| 1172 // http://crbug.com/90971 | 1189 // http://crbug.com/90971 |
| 1173 CHECK(ContainsKey(active_resource_contexts_, resource_context)); | 1190 CHECK(ContainsKey(active_resource_contexts_, resource_context)); |
| 1174 | 1191 |
| 1192 // Parse the headers before calling ShouldServiceRequest, so that they are | |
| 1193 // available to be validated. | |
| 1194 net::HttpRequestHeaders headers; | |
| 1195 headers.AddHeadersFromString(request_data.headers); | |
| 1196 | |
| 1175 if (is_shutdown_ || | 1197 if (is_shutdown_ || |
| 1176 !ShouldServiceRequest(process_type, child_id, request_data, | 1198 !ShouldServiceRequest(process_type, child_id, request_data, headers, |
| 1177 filter_->file_system_context())) { | 1199 filter_, resource_context)) { |
| 1178 AbortRequestBeforeItStarts(filter_, sync_result, request_id); | 1200 AbortRequestBeforeItStarts(filter_, sync_result, request_id); |
| 1179 return; | 1201 return; |
| 1180 } | 1202 } |
| 1181 | 1203 |
| 1182 // Allow the observer to block/handle the request. | 1204 // Allow the observer to block/handle the request. |
| 1183 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method, | 1205 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method, |
| 1184 request_data.url, | 1206 request_data.url, |
| 1185 request_data.resource_type, | 1207 request_data.resource_type, |
| 1186 resource_context)) { | 1208 resource_context)) { |
| 1187 AbortRequestBeforeItStarts(filter_, sync_result, request_id); | 1209 AbortRequestBeforeItStarts(filter_, sync_result, request_id); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1199 // If the request is a MAIN_FRAME request, the first-party URL gets updated on | 1221 // If the request is a MAIN_FRAME request, the first-party URL gets updated on |
| 1200 // redirects. | 1222 // redirects. |
| 1201 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME) { | 1223 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME) { |
| 1202 new_request->set_first_party_url_policy( | 1224 new_request->set_first_party_url_policy( |
| 1203 net::URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT); | 1225 net::URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT); |
| 1204 } | 1226 } |
| 1205 | 1227 |
| 1206 const Referrer referrer(request_data.referrer, request_data.referrer_policy); | 1228 const Referrer referrer(request_data.referrer, request_data.referrer_policy); |
| 1207 SetReferrerForRequest(new_request.get(), referrer); | 1229 SetReferrerForRequest(new_request.get(), referrer); |
| 1208 | 1230 |
| 1209 net::HttpRequestHeaders headers; | |
| 1210 headers.AddHeadersFromString(request_data.headers); | |
| 1211 new_request->SetExtraRequestHeaders(headers); | 1231 new_request->SetExtraRequestHeaders(headers); |
| 1212 | 1232 |
| 1213 storage::BlobStorageContext* blob_context = | 1233 storage::BlobStorageContext* blob_context = |
| 1214 GetBlobStorageContext(filter_->blob_storage_context()); | 1234 GetBlobStorageContext(filter_->blob_storage_context()); |
| 1215 // Resolve elements from request_body and prepare upload data. | 1235 // Resolve elements from request_body and prepare upload data. |
| 1216 if (request_data.request_body.get()) { | 1236 if (request_data.request_body.get()) { |
| 1217 // |blob_context| could be null when the request is from the plugins because | 1237 // |blob_context| could be null when the request is from the plugins because |
| 1218 // ResourceMessageFilters created in PluginProcessHost don't have the blob | 1238 // ResourceMessageFilters created in PluginProcessHost don't have the blob |
| 1219 // context. | 1239 // context. |
| 1220 if (blob_context) { | 1240 if (blob_context) { |
| (...skipping 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2371 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS) | 2391 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS) |
| 2372 && !policy->CanReadRawCookies(child_id)) { | 2392 && !policy->CanReadRawCookies(child_id)) { |
| 2373 VLOG(1) << "Denied unauthorized request for raw headers"; | 2393 VLOG(1) << "Denied unauthorized request for raw headers"; |
| 2374 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS; | 2394 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS; |
| 2375 } | 2395 } |
| 2376 | 2396 |
| 2377 return load_flags; | 2397 return load_flags; |
| 2378 } | 2398 } |
| 2379 | 2399 |
| 2380 } // namespace content | 2400 } // namespace content |
| OLD | NEW |