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

Side by Side Diff: third_party/WebKit/Source/platform/loader/fetch/CrossOriginAccessControl.cpp

Issue 2807073002: Removed local RefPtr objects created from PassRefPtr arguments. (Closed)
Patch Set: Created 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 "' contains a username and password, which is disallowed for" 465 "' contains a username and password, which is disallowed for"
466 " cross-origin requests."); 466 " cross-origin requests.");
467 return; 467 return;
468 } 468 }
469 default: 469 default:
470 NOTREACHED(); 470 NOTREACHED();
471 } 471 }
472 } 472 }
473 473
474 bool CrossOriginAccessControl::HandleRedirect( 474 bool CrossOriginAccessControl::HandleRedirect(
475 PassRefPtr<SecurityOrigin> security_origin, 475 RefPtr<SecurityOrigin> security_origin,
476 ResourceRequest& new_request, 476 ResourceRequest& new_request,
477 const ResourceResponse& redirect_response, 477 const ResourceResponse& redirect_response,
478 StoredCredentials with_credentials, 478 StoredCredentials with_credentials,
479 ResourceLoaderOptions& options, 479 ResourceLoaderOptions& options,
480 String& error_message) { 480 String& error_message) {
481 // http://www.w3.org/TR/cors/#redirect-steps terminology: 481 // http://www.w3.org/TR/cors/#redirect-steps terminology:
482 const KURL& last_url = redirect_response.Url(); 482 const KURL& last_url = redirect_response.Url();
483 const KURL& new_url = new_request.Url(); 483 const KURL& new_url = new_request.Url();
484 484
485 RefPtr<SecurityOrigin> current_security_origin = security_origin; 485 RefPtr<SecurityOrigin> new_security_origin = security_origin;
486
487 RefPtr<SecurityOrigin> new_security_origin = current_security_origin;
Yuta Kitamura 2017/04/10 07:00:11 I think the removal of new_security_origin causes
Bugs Nash 2017/04/11 01:47:51 I'm not removing new_security_origin, I'm setting
Yuta Kitamura 2017/04/11 05:49:39 Ah I see, I now see you didn't change the behavior
488 486
489 // TODO(tyoshino): This should be fixed to check not only the last one but 487 // TODO(tyoshino): This should be fixed to check not only the last one but
490 // all redirect responses. 488 // all redirect responses.
491 if (!current_security_origin->CanRequest(last_url)) { 489 if (!security_origin->CanRequest(last_url)) {
492 // Follow http://www.w3.org/TR/cors/#redirect-steps 490 // Follow http://www.w3.org/TR/cors/#redirect-steps
493 CrossOriginAccessControl::RedirectStatus redirect_status = 491 CrossOriginAccessControl::RedirectStatus redirect_status =
494 CrossOriginAccessControl::CheckRedirectLocation(new_url); 492 CrossOriginAccessControl::CheckRedirectLocation(new_url);
495 if (redirect_status != kRedirectSuccess) { 493 if (redirect_status != kRedirectSuccess) {
496 StringBuilder builder; 494 StringBuilder builder;
497 builder.Append("Redirect from '"); 495 builder.Append("Redirect from '");
498 builder.Append(last_url.GetString()); 496 builder.Append(last_url.GetString());
499 builder.Append("' has been blocked by CORS policy: "); 497 builder.Append("' has been blocked by CORS policy: ");
500 CrossOriginAccessControl::RedirectErrorString(builder, redirect_status, 498 CrossOriginAccessControl::RedirectErrorString(builder, redirect_status,
501 new_url); 499 new_url);
502 error_message = builder.ToString(); 500 error_message = builder.ToString();
503 return false; 501 return false;
504 } 502 }
505 503
506 // Step 5: perform resource sharing access check. 504 // Step 5: perform resource sharing access check.
507 CrossOriginAccessControl::AccessStatus cors_status = 505 CrossOriginAccessControl::AccessStatus cors_status =
508 CrossOriginAccessControl::CheckAccess( 506 CrossOriginAccessControl::CheckAccess(
509 redirect_response, with_credentials, current_security_origin.Get()); 507 redirect_response, with_credentials, security_origin.Get());
510 if (cors_status != kAccessAllowed) { 508 if (cors_status != kAccessAllowed) {
511 StringBuilder builder; 509 StringBuilder builder;
512 builder.Append("Redirect from '"); 510 builder.Append("Redirect from '");
513 builder.Append(last_url.GetString()); 511 builder.Append(last_url.GetString());
514 builder.Append("' has been blocked by CORS policy: "); 512 builder.Append("' has been blocked by CORS policy: ");
515 CrossOriginAccessControl::AccessControlErrorString( 513 CrossOriginAccessControl::AccessControlErrorString(
516 builder, cors_status, redirect_response, 514 builder, cors_status, redirect_response, security_origin.Get(),
517 current_security_origin.Get(), new_request.GetRequestContext()); 515 new_request.GetRequestContext());
518 error_message = builder.ToString(); 516 error_message = builder.ToString();
519 return false; 517 return false;
520 } 518 }
521 519
522 RefPtr<SecurityOrigin> last_origin = SecurityOrigin::Create(last_url); 520 RefPtr<SecurityOrigin> last_origin = SecurityOrigin::Create(last_url);
523 // Set request's origin to a globally unique identifier as specified in 521 // Set request's origin to a globally unique identifier as specified in
524 // the step 10 in https://fetch.spec.whatwg.org/#http-redirect-fetch. 522 // the step 10 in https://fetch.spec.whatwg.org/#http-redirect-fetch.
525 if (!last_origin->CanRequest(new_url)) { 523 if (!last_origin->CanRequest(new_url)) {
526 options.security_origin = SecurityOrigin::CreateUnique(); 524 options.security_origin = SecurityOrigin::CreateUnique();
527 new_security_origin = options.security_origin; 525 new_security_origin = options.security_origin;
528 } 526 }
529 } 527 }
530 528
531 if (!current_security_origin->CanRequest(new_url)) { 529 if (!security_origin->CanRequest(new_url)) {
532 new_request.ClearHTTPOrigin(); 530 new_request.ClearHTTPOrigin();
533 new_request.SetHTTPOrigin(new_security_origin.Get()); 531 new_request.SetHTTPOrigin(new_security_origin.Get());
534 532
535 // Unset credentials flag if request's credentials mode is "same-origin" as 533 // Unset credentials flag if request's credentials mode is "same-origin" as
536 // request's response tainting becomes "cors". 534 // request's response tainting becomes "cors".
537 // 535 //
538 // This is equivalent to the step 2 in 536 // This is equivalent to the step 2 in
539 // https://fetch.spec.whatwg.org/#http-network-or-cache-fetch 537 // https://fetch.spec.whatwg.org/#http-network-or-cache-fetch
540 if (options.credentials_requested == kClientDidNotRequestCredentials) 538 if (options.credentials_requested == kClientDidNotRequestCredentials)
541 options.allow_credentials = kDoNotAllowStoredCredentials; 539 options.allow_credentials = kDoNotAllowStoredCredentials;
542 } 540 }
543 return true; 541 return true;
544 } 542 }
545 543
546 } // namespace blink 544 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698