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

Side by Side Diff: content/browser/loader/resource_dispatcher_host_impl.cc

Issue 1903133004: Report invalid URLs as ERR_INVALID_URL rather than ERR_ABORTED (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a test Created 4 years, 8 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 | « no previous file | content/browser/loader/resource_dispatcher_host_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // 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 <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 case RESOURCE_TYPE_PREFETCH: 218 case RESOURCE_TYPE_PREFETCH:
219 case RESOURCE_TYPE_PING: 219 case RESOURCE_TYPE_PING:
220 case RESOURCE_TYPE_CSP_REPORT: 220 case RESOURCE_TYPE_CSP_REPORT:
221 return true; 221 return true;
222 default: 222 default:
223 return false; 223 return false;
224 } 224 }
225 } 225 }
226 226
227 // Aborts a request before an URLRequest has actually been created. 227 // Aborts a request before an URLRequest has actually been created.
228 void AbortRequestBeforeItStarts(ResourceMessageFilter* filter, 228 void AbortRequestBeforeItStarts(ResourceMessageFilter* filter,
mmenke 2016/04/21 15:28:15 Abort -> Fail?
davidben 2016/04/21 19:00:25 Done.
229 IPC::Message* sync_result, 229 IPC::Message* sync_result,
230 int request_id) { 230 int request_id,
231 net::Error error) {
231 if (sync_result) { 232 if (sync_result) {
232 SyncLoadResult result; 233 SyncLoadResult result;
233 result.error_code = net::ERR_ABORTED; 234 result.error_code = error;
234 ResourceHostMsg_SyncLoad::WriteReplyParams(sync_result, result); 235 ResourceHostMsg_SyncLoad::WriteReplyParams(sync_result, result);
235 filter->Send(sync_result); 236 filter->Send(sync_result);
236 } else { 237 } else {
237 // Tell the renderer that this request was disallowed. 238 // Tell the renderer that this request was disallowed.
238 ResourceMsg_RequestCompleteData request_complete_data; 239 ResourceMsg_RequestCompleteData request_complete_data;
239 request_complete_data.error_code = net::ERR_ABORTED; 240 request_complete_data.error_code = error;
240 request_complete_data.was_ignored_by_handler = false; 241 request_complete_data.was_ignored_by_handler = false;
241 request_complete_data.exists_in_cache = false; 242 request_complete_data.exists_in_cache = false;
242 // No security info needed, connection not established. 243 // No security info needed, connection not established.
243 request_complete_data.completion_time = base::TimeTicks(); 244 request_complete_data.completion_time = base::TimeTicks();
244 request_complete_data.encoded_data_length = 0; 245 request_complete_data.encoded_data_length = 0;
245 filter->Send(new ResourceMsg_RequestComplete( 246 filter->Send(new ResourceMsg_RequestComplete(
246 request_id, request_complete_data)); 247 request_id, request_complete_data));
247 } 248 }
248 } 249 }
249 250
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 break; 283 break;
283 case blink::WebReferrerPolicyNoReferrerWhenDowngradeOriginWhenCrossOrigin: 284 case blink::WebReferrerPolicyNoReferrerWhenDowngradeOriginWhenCrossOrigin:
284 net_referrer_policy = net::URLRequest:: 285 net_referrer_policy = net::URLRequest::
285 REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN; 286 REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN;
286 break; 287 break;
287 } 288 }
288 request->set_referrer_policy(net_referrer_policy); 289 request->set_referrer_policy(net_referrer_policy);
289 } 290 }
290 291
291 // Consults the RendererSecurity policy to determine whether the 292 // Consults the RendererSecurity policy to determine whether the
292 // ResourceDispatcherHostImpl should service this request. A request might be 293 // ResourceDispatcherHostImpl should service this request. Returns net::OK if
293 // disallowed if the renderer is not authorized to retrieve the request URL or 294 // allowed or a net error otherwise. A request might be disallowed if the
294 // if the renderer is attempting to upload an unauthorized file. 295 // renderer is not authorized to retrieve the request URL or if the renderer is
295 bool ShouldServiceRequest(int process_type, 296 // attempting to upload an unauthorized file.
296 int child_id, 297 net::Error ShouldServiceRequest(int process_type,
297 const ResourceHostMsg_Request& request_data, 298 int child_id,
298 const net::HttpRequestHeaders& headers, 299 const ResourceHostMsg_Request& request_data,
299 ResourceMessageFilter* filter, 300 const net::HttpRequestHeaders& headers,
300 ResourceContext* resource_context) { 301 ResourceMessageFilter* filter,
302 ResourceContext* resource_context) {
301 ChildProcessSecurityPolicyImpl* policy = 303 ChildProcessSecurityPolicyImpl* policy =
302 ChildProcessSecurityPolicyImpl::GetInstance(); 304 ChildProcessSecurityPolicyImpl::GetInstance();
303 305
304 // Check if the renderer is permitted to request the requested URL. 306 // Check if the renderer is permitted to request the requested URL.
305 if (!policy->CanRequestURL(child_id, request_data.url)) { 307 if (!policy->CanRequestURL(child_id, request_data.url)) {
306 VLOG(1) << "Denied unauthorized request for " 308 VLOG(1) << "Denied unauthorized request for "
307 << request_data.url.possibly_invalid_spec(); 309 << request_data.url.possibly_invalid_spec();
308 return false; 310 return net::ERR_INVALID_URL;
mmenke 2016/04/21 15:28:15 Also, I think F5 / reload is the reason not to com
mmenke 2016/04/21 15:28:15 This seem a fine error code for !url.is_valid(), b
davidben 2016/04/21 19:00:25 It doesn't commit with the new URL, actually. Just
davidben 2016/04/21 19:00:25 The other cases are things like magic schemes or s
mmenke 2016/04/21 19:10:05 How does it know not to commit with the new URL?
davidben 2016/04/21 19:20:04 Oh hrm, that's true. I was thinking redirects wher
nasko 2016/04/21 20:30:00 I had this comment typed up in a previous version
davidben 2016/04/29 21:54:40 There's ERR_ACCESS_DENIED. The nuisance is that th
309 } 311 }
310 312
311 // Check if the renderer is using an illegal Origin header. If so, kill it. 313 // Check if the renderer is using an illegal Origin header. If so, kill it.
312 std::string origin_string; 314 std::string origin_string;
313 bool has_origin = headers.GetHeader("Origin", &origin_string) && 315 bool has_origin = headers.GetHeader("Origin", &origin_string) &&
314 origin_string != "null"; 316 origin_string != "null";
315 if (has_origin) { 317 if (has_origin) {
316 GURL origin(origin_string); 318 GURL origin(origin_string);
317 if (!policy->CanCommitURL(child_id, origin) || 319 if (!policy->CanCommitURL(child_id, origin) ||
318 GetContentClient()->browser()->IsIllegalOrigin(resource_context, 320 GetContentClient()->browser()->IsIllegalOrigin(resource_context,
319 child_id, origin)) { 321 child_id, origin)) {
320 VLOG(1) << "Killed renderer for illegal origin: " << origin_string; 322 VLOG(1) << "Killed renderer for illegal origin: " << origin_string;
321 bad_message::ReceivedBadMessage(filter, bad_message::RDH_ILLEGAL_ORIGIN); 323 bad_message::ReceivedBadMessage(filter, bad_message::RDH_ILLEGAL_ORIGIN);
322 return false; 324 return net::ERR_INVALID_URL;
323 } 325 }
324 } 326 }
325 327
326 // Check if the renderer is permitted to upload the requested files. 328 // Check if the renderer is permitted to upload the requested files.
327 if (request_data.request_body.get()) { 329 if (request_data.request_body.get()) {
328 const std::vector<ResourceRequestBody::Element>* uploads = 330 const std::vector<ResourceRequestBody::Element>* uploads =
329 request_data.request_body->elements(); 331 request_data.request_body->elements();
330 std::vector<ResourceRequestBody::Element>::const_iterator iter; 332 std::vector<ResourceRequestBody::Element>::const_iterator iter;
331 for (iter = uploads->begin(); iter != uploads->end(); ++iter) { 333 for (iter = uploads->begin(); iter != uploads->end(); ++iter) {
332 if (iter->type() == ResourceRequestBody::Element::TYPE_FILE && 334 if (iter->type() == ResourceRequestBody::Element::TYPE_FILE &&
333 !policy->CanReadFile(child_id, iter->path())) { 335 !policy->CanReadFile(child_id, iter->path())) {
334 NOTREACHED() << "Denied unauthorized upload of " 336 NOTREACHED() << "Denied unauthorized upload of "
335 << iter->path().value(); 337 << iter->path().value();
336 return false; 338 return net::ERR_ACCESS_DENIED;
337 } 339 }
338 if (iter->type() == ResourceRequestBody::Element::TYPE_FILE_FILESYSTEM) { 340 if (iter->type() == ResourceRequestBody::Element::TYPE_FILE_FILESYSTEM) {
339 storage::FileSystemURL url = 341 storage::FileSystemURL url =
340 filter->file_system_context()->CrackURL(iter->filesystem_url()); 342 filter->file_system_context()->CrackURL(iter->filesystem_url());
341 if (!policy->CanReadFileSystemFile(child_id, url)) { 343 if (!policy->CanReadFileSystemFile(child_id, url)) {
342 NOTREACHED() << "Denied unauthorized upload of " 344 NOTREACHED() << "Denied unauthorized upload of "
343 << iter->filesystem_url().spec(); 345 << iter->filesystem_url().spec();
344 return false; 346 return net::ERR_ACCESS_DENIED;
345 } 347 }
346 } 348 }
347 } 349 }
348 } 350 }
349 351
350 return true; 352 return net::OK;
351 } 353 }
352 354
353 void RemoveDownloadFileFromChildSecurityPolicy(int child_id, 355 void RemoveDownloadFileFromChildSecurityPolicy(int child_id,
354 const base::FilePath& path) { 356 const base::FilePath& path) {
355 ChildProcessSecurityPolicyImpl::GetInstance()->RevokeAllPermissionsForFile( 357 ChildProcessSecurityPolicyImpl::GetInstance()->RevokeAllPermissionsForFile(
356 child_id, path); 358 child_id, path);
357 } 359 }
358 360
359 int GetCertID(CertStore* cert_store, net::URLRequest* request, int child_id) { 361 int GetCertID(CertStore* cert_store, net::URLRequest* request, int child_id) {
360 if (request->ssl_info().cert.get()) 362 if (request->ssl_info().cert.get())
(...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after
1426 filter_->GetContexts(request_data.resource_type, request_data.origin_pid, 1428 filter_->GetContexts(request_data.resource_type, request_data.origin_pid,
1427 &resource_context, &request_context); 1429 &resource_context, &request_context);
1428 // http://crbug.com/90971 1430 // http://crbug.com/90971
1429 CHECK(ContainsKey(active_resource_contexts_, resource_context)); 1431 CHECK(ContainsKey(active_resource_contexts_, resource_context));
1430 1432
1431 // Parse the headers before calling ShouldServiceRequest, so that they are 1433 // Parse the headers before calling ShouldServiceRequest, so that they are
1432 // available to be validated. 1434 // available to be validated.
1433 net::HttpRequestHeaders headers; 1435 net::HttpRequestHeaders headers;
1434 headers.AddHeadersFromString(request_data.headers); 1436 headers.AddHeadersFromString(request_data.headers);
1435 1437
1436 if (is_shutdown_ || 1438 if (is_shutdown_) {
1437 !ShouldServiceRequest(process_type, child_id, request_data, headers, 1439 AbortRequestBeforeItStarts(filter_, sync_result, request_id,
1438 filter_, resource_context)) { 1440 net::ERR_ABORTED);
1439 AbortRequestBeforeItStarts(filter_, sync_result, request_id); 1441 return;
1442 }
1443 net::Error error = ShouldServiceRequest(process_type, child_id, request_data,
1444 headers, filter_, resource_context);
1445 if (error != net::OK) {
1446 AbortRequestBeforeItStarts(filter_, sync_result, request_id, error);
1440 return; 1447 return;
1441 } 1448 }
1442 1449
1443 // Allow the observer to block/handle the request. 1450 // Allow the observer to block/handle the request.
1444 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method, 1451 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method,
1445 request_data.url, 1452 request_data.url,
1446 request_data.resource_type, 1453 request_data.resource_type,
1447 resource_context)) { 1454 resource_context)) {
1448 AbortRequestBeforeItStarts(filter_, sync_result, request_id); 1455 AbortRequestBeforeItStarts(filter_, sync_result, request_id,
1456 net::ERR_ABORTED);
1449 return; 1457 return;
1450 } 1458 }
1451 1459
1452 // Construct the request. 1460 // Construct the request.
1453 std::unique_ptr<net::URLRequest> new_request = request_context->CreateRequest( 1461 std::unique_ptr<net::URLRequest> new_request = request_context->CreateRequest(
1454 is_navigation_stream_request ? request_data.resource_body_stream_url 1462 is_navigation_stream_request ? request_data.resource_body_stream_url
1455 : request_data.url, 1463 : request_data.url,
1456 request_data.priority, nullptr); 1464 request_data.priority, nullptr);
1457 1465
1458 // PlzNavigate: Always set the method to GET when gaining access to the 1466 // PlzNavigate: Always set the method to GET when gaining access to the
(...skipping 1229 matching lines...) Expand 10 before | Expand all | Expand 10 after
2688 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); 2696 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id);
2689 response->head.security_info = SerializeSecurityInfo(ssl); 2697 response->head.security_info = SerializeSecurityInfo(ssl);
2690 } 2698 }
2691 2699
2692 CertStore* ResourceDispatcherHostImpl::GetCertStore() { 2700 CertStore* ResourceDispatcherHostImpl::GetCertStore() {
2693 return cert_store_for_testing_ ? cert_store_for_testing_ 2701 return cert_store_for_testing_ ? cert_store_for_testing_
2694 : CertStore::GetInstance(); 2702 : CertStore::GetInstance();
2695 } 2703 }
2696 2704
2697 } // namespace content 2705 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/loader/resource_dispatcher_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698