Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2013, Intel Corporation | 3 * Copyright (C) 2013, Intel Corporation |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 if (isAllowedRedirect(request.url())) { | 199 if (isAllowedRedirect(request.url())) { |
| 200 if (m_client->isDocumentThreadableLoaderClient()) | 200 if (m_client->isDocumentThreadableLoaderClient()) |
| 201 static_cast<DocumentThreadableLoaderClient*>(m_client)->willSendRequ est(request, redirectResponse); | 201 static_cast<DocumentThreadableLoaderClient*>(m_client)->willSendRequ est(request, redirectResponse); |
| 202 return; | 202 return; |
| 203 } | 203 } |
| 204 | 204 |
| 205 // When using access control, only simple cross origin requests are allowed to redirect. The new request URL must have a supported | 205 // When using access control, only simple cross origin requests are allowed to redirect. The new request URL must have a supported |
| 206 // scheme and not contain the userinfo production. In addition, the redirect response must pass the access control check if the | 206 // scheme and not contain the userinfo production. In addition, the redirect response must pass the access control check if the |
| 207 // original request was not same-origin. | 207 // original request was not same-origin. |
| 208 if (m_options.crossOriginRequestPolicy == UseAccessControl) { | 208 if (m_options.crossOriginRequestPolicy == UseAccessControl) { |
| 209 | |
| 210 InspectorInstrumentation::didReceiveCORSRedirectResponse(m_document->fra me(), resource->identifier(), m_document->frame()->loader()->documentLoader(), r edirectResponse, 0); | |
| 211 | |
| 209 bool allowRedirect = false; | 212 bool allowRedirect = false; |
| 213 String accessControlErrorDescription; | |
| 214 | |
| 210 if (m_simpleRequest) { | 215 if (m_simpleRequest) { |
| 211 String accessControlErrorDescription; | 216 allowRedirect = checkCrossOriginAccessRedirectionUrl(request.url(), accessControlErrorDescription) |
| 212 allowRedirect = SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(re quest.url().protocol()) | |
| 213 && request.url().user().isEmpty() | |
| 214 && request.url().pass().isEmpty() | |
| 215 && (m_sameOriginRequest || passesAccessControlCheck( redirectResponse, m_options.allowCredentials, securityOrigin(), accessControlErr orDescription)); | 217 && (m_sameOriginRequest || passesAccessControlCheck( redirectResponse, m_options.allowCredentials, securityOrigin(), accessControlErr orDescription)); |
| 218 } else { | |
| 219 accessControlErrorDescription = "The request was redirected to '"+ r equest.url().string() + "', which is disallowed for cross-origin requests that r equire preflight."; | |
| 216 } | 220 } |
| 217 | 221 |
| 218 if (allowRedirect) { | 222 if (allowRedirect) { |
| 219 if (m_resource) | 223 if (m_resource) |
| 220 clearResource(); | 224 clearResource(); |
| 221 | 225 |
| 222 RefPtr<SecurityOrigin> originalOrigin = SecurityOrigin::create(redir ectResponse.url()); | 226 RefPtr<SecurityOrigin> originalOrigin = SecurityOrigin::create(redir ectResponse.url()); |
| 223 RefPtr<SecurityOrigin> requestOrigin = SecurityOrigin::create(reques t.url()); | 227 RefPtr<SecurityOrigin> requestOrigin = SecurityOrigin::create(reques t.url()); |
| 224 // If the original request wasn't same-origin, then if the request U RL origin is not same origin with the original URL origin, | 228 // If the original request wasn't same-origin, then if the request U RL origin is not same origin with the original URL origin, |
| 225 // set the source origin to a globally unique identifier. (If the or iginal request was same-origin, the origin of the new request | 229 // set the source origin to a globally unique identifier. (If the or iginal request was same-origin, the origin of the new request |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 236 | 240 |
| 237 // Remove any headers that may have been added by the network layer that cause access control to fail. | 241 // Remove any headers that may have been added by the network layer that cause access control to fail. |
| 238 request.clearHTTPContentType(); | 242 request.clearHTTPContentType(); |
| 239 request.clearHTTPReferrer(); | 243 request.clearHTTPReferrer(); |
| 240 request.clearHTTPOrigin(); | 244 request.clearHTTPOrigin(); |
| 241 request.clearHTTPUserAgent(); | 245 request.clearHTTPUserAgent(); |
| 242 request.clearHTTPAccept(); | 246 request.clearHTTPAccept(); |
| 243 makeCrossOriginAccessRequest(request); | 247 makeCrossOriginAccessRequest(request); |
| 244 return; | 248 return; |
| 245 } | 249 } |
| 250 | |
| 251 ResourceError error(errorDomainWebKitInternal, 0, redirectResponse.url() .string(), accessControlErrorDescription); | |
| 252 m_client->didFailAccessControlCheck(error); | |
| 253 } else { | |
| 254 m_client->didFailRedirectCheck(); | |
| 246 } | 255 } |
| 247 | |
| 248 m_client->didFailRedirectCheck(); | |
| 249 request = ResourceRequest(); | 256 request = ResourceRequest(); |
| 250 } | 257 } |
| 251 | 258 |
| 252 void DocumentThreadableLoader::dataSent(Resource* resource, unsigned long long b ytesSent, unsigned long long totalBytesToBeSent) | 259 void DocumentThreadableLoader::dataSent(Resource* resource, unsigned long long b ytesSent, unsigned long long totalBytesToBeSent) |
| 253 { | 260 { |
| 254 ASSERT(m_client); | 261 ASSERT(m_client); |
| 255 ASSERT_UNUSED(resource, resource == m_resource); | 262 ASSERT_UNUSED(resource, resource == m_resource); |
| 256 m_client->didSendData(bytesSent, totalBytesToBeSent); | 263 m_client->didSendData(bytesSent, totalBytesToBeSent); |
| 257 } | 264 } |
| 258 | 265 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 485 if (m_options.contentSecurityPolicyEnforcement != EnforceConnectSrcDirective ) | 492 if (m_options.contentSecurityPolicyEnforcement != EnforceConnectSrcDirective ) |
| 486 return true; | 493 return true; |
| 487 return m_document->contentSecurityPolicy()->allowConnectToSource(url); | 494 return m_document->contentSecurityPolicy()->allowConnectToSource(url); |
| 488 } | 495 } |
| 489 | 496 |
| 490 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const | 497 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const |
| 491 { | 498 { |
| 492 return m_options.securityOrigin ? m_options.securityOrigin.get() : m_documen t->securityOrigin(); | 499 return m_options.securityOrigin ? m_options.securityOrigin.get() : m_documen t->securityOrigin(); |
| 493 } | 500 } |
| 494 | 501 |
| 502 bool DocumentThreadableLoader::checkCrossOriginAccessRedirectionUrl(const KURL& requestUrl, String& errorDescription) | |
| 503 { | |
| 504 if (!SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(requestUrl.protocol() )) { | |
| 505 errorDescription = "The request was redirected to a URL ('" + requestUrl .string() + "') which has a disallowed scheme for cross-origin requests."; | |
| 506 return false; | |
| 507 } | |
| 508 | |
| 509 if (!(requestUrl.user().isEmpty() && requestUrl.pass().isEmpty())) { | |
| 510 errorDescription = "The request was redirected to a URL ('" + requestUrl .string() + "') containing userinfo, which is disallowed for cross-origin reques ts."; | |
| 511 return false; | |
| 512 } | |
| 513 | |
| 514 return true; | |
| 515 } | |
| 516 | |
| 495 } // namespace WebCore | 517 } // namespace WebCore |
|
ancilgeorge
2013/08/29 08:09:58
nit. Removed the extra enter.
| |
| OLD | NEW |