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

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

Issue 1196423003: Improve console log message for CORS failure (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase, Addressed #9 Created 4 years, 5 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 headerSet.add(header); 261 headerSet.add(header);
262 return; 262 return;
263 } 263 }
264 parseAccessControlExposeHeadersAllowList(response.httpHeaderField(HTTPNames: :Access_Control_Expose_Headers), headerSet); 264 parseAccessControlExposeHeadersAllowList(response.httpHeaderField(HTTPNames: :Access_Control_Expose_Headers), headerSet);
265 } 265 }
266 266
267 bool CrossOriginAccessControl::isLegalRedirectLocation(const KURL& requestURL, S tring& errorDescription) 267 bool CrossOriginAccessControl::isLegalRedirectLocation(const KURL& requestURL, S tring& errorDescription)
268 { 268 {
269 // CORS restrictions imposed on Location: URL -- http://www.w3.org/TR/cors/# redirect-steps (steps 2 + 3.) 269 // CORS restrictions imposed on Location: URL -- http://www.w3.org/TR/cors/# redirect-steps (steps 2 + 3.)
270 if (!SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(requestURL.protocol() )) { 270 if (!SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(requestURL.protocol() )) {
271 errorDescription = "The request was redirected to a URL ('" + requestURL .getString() + "') which has a disallowed scheme for cross-origin requests."; 271 errorDescription = "Redirect location '" + requestURL.getString() + "' h as a disallowed scheme for cross-origin requests.";
272 return false; 272 return false;
273 } 273 }
274 274
275 if (!(requestURL.user().isEmpty() && requestURL.pass().isEmpty())) { 275 if (!(requestURL.user().isEmpty() && requestURL.pass().isEmpty())) {
276 errorDescription = "The request was redirected to a URL ('" + requestURL .getString() + "') containing userinfo, which is disallowed for cross-origin req uests."; 276 errorDescription = "Redirect location '" + requestURL.getString() + "' c ontains userinfo, which is disallowed for cross-origin requests.";
277 return false; 277 return false;
278 } 278 }
279 279
280 return true; 280 return true;
281 } 281 }
282 282
283 bool CrossOriginAccessControl::handleRedirect(SecurityOrigin* securityOrigin, Re sourceRequest& newRequest, const ResourceResponse& redirectResponse, StoredCrede ntials withCredentials, ResourceLoaderOptions& options, String& errorMessage) 283 bool CrossOriginAccessControl::handleRedirect(SecurityOrigin* securityOrigin, Re sourceRequest& newRequest, const ResourceResponse& redirectResponse, StoredCrede ntials withCredentials, ResourceLoaderOptions& options, String& errorMessage)
284 { 284 {
285 // http://www.w3.org/TR/cors/#redirect-steps terminology: 285 // http://www.w3.org/TR/cors/#redirect-steps terminology:
286 const KURL& originalURL = redirectResponse.url(); 286 const KURL& originalURL = redirectResponse.url();
287 const KURL& newURL = newRequest.url(); 287 const KURL& newURL = newRequest.url();
288 288
289 bool redirectCrossOrigin = !securityOrigin->canRequest(newURL); 289 bool redirectCrossOrigin = !securityOrigin->canRequest(newURL);
290 290
291 // Same-origin request URLs that redirect are allowed without checking acces s. 291 // Same-origin request URLs that redirect are allowed without checking acces s.
292 if (!securityOrigin->canRequest(originalURL)) { 292 if (!securityOrigin->canRequest(originalURL)) {
293 // Follow http://www.w3.org/TR/cors/#redirect-steps 293 // Follow http://www.w3.org/TR/cors/#redirect-steps
294 String errorDescription; 294 String errorDescription;
295 295
296 // Steps 3 & 4 - check if scheme and other URL restrictions hold. 296 // Steps 3 & 4 - check if scheme and other URL restrictions hold.
297 bool allowRedirect = isLegalRedirectLocation(newURL, errorDescription); 297 if (!isLegalRedirectLocation(newURL, errorDescription)) {
298 if (allowRedirect) { 298 errorMessage = "Redirect from '" + originalURL.getString() + "' has been blocked by CORS policy: " + errorDescription;
299 // Step 5: perform resource sharing access check. 299 return false;
300 allowRedirect = passesAccessControlCheck(redirectResponse, withCrede ntials, securityOrigin, errorDescription, newRequest.requestContext());
301 if (allowRedirect) {
302 RefPtr<SecurityOrigin> originalOrigin = SecurityOrigin::create(o riginalURL);
303 // Step 6: if the request URL origin is not same origin as the o riginal URL's,
304 // set the source origin to a globally unique identifier.
305 if (!originalOrigin->canRequest(newURL)) {
306 options.securityOrigin = SecurityOrigin::createUnique();
307 securityOrigin = options.securityOrigin.get();
308 }
309 }
310 } 300 }
311 if (!allowRedirect) { 301
312 const String& originalOrigin = SecurityOrigin::create(originalURL)-> toString(); 302 // Step 5: perform resource sharing access check.
313 errorMessage = "Redirect at origin '" + originalOrigin + "' has been blocked from loading by Cross-Origin Resource Sharing policy: " + errorDescript ion; 303 if (!passesAccessControlCheck(redirectResponse, withCredentials, securit yOrigin, errorDescription, newRequest.requestContext())) {
304 errorMessage = "Redirect from '" + originalURL.getString() + "' has been blocked by CORS policy: Redirect response does not pass CORS check: '" + er rorDescription;
sof 2016/07/27 11:51:03 I'll leave it up to you to make a final decision,
tyoshino (SeeGerritForStatus) 2016/07/28 12:23:05 Hmm, ok. Removed.
314 return false; 305 return false;
315 } 306 }
307
308 RefPtr<SecurityOrigin> originalOrigin = SecurityOrigin::create(originalU RL);
309 // Step 6: if the request URL origin is not same origin as the original URL's,
310 // set the source origin to a globally unique identifier.
311 if (!originalOrigin->canRequest(newURL)) {
312 options.securityOrigin = SecurityOrigin::createUnique();
313 securityOrigin = options.securityOrigin.get();
314 }
316 } 315 }
317 if (redirectCrossOrigin) { 316 if (redirectCrossOrigin) {
318 // If now to a different origin, update/set Origin:. 317 // If now to a different origin, update/set Origin:.
319 newRequest.clearHTTPOrigin(); 318 newRequest.clearHTTPOrigin();
320 newRequest.setHTTPOrigin(securityOrigin); 319 newRequest.setHTTPOrigin(securityOrigin);
321 // If the user didn't request credentials in the first place, update our 320 // If the user didn't request credentials in the first place, update our
322 // state so we neither request them nor expect they must be allowed. 321 // state so we neither request them nor expect they must be allowed.
323 if (options.credentialsRequested == ClientDidNotRequestCredentials) 322 if (options.credentialsRequested == ClientDidNotRequestCredentials)
324 options.allowCredentials = DoNotAllowStoredCredentials; 323 options.allowCredentials = DoNotAllowStoredCredentials;
325 } 324 }
326 return true; 325 return true;
327 } 326 }
328 327
329 } // namespace blink 328 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698