| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 155 |
| 156 void DocumentThreadableLoader::makeCrossOriginAccessRequest(const ResourceReques
t& request) | 156 void DocumentThreadableLoader::makeCrossOriginAccessRequest(const ResourceReques
t& request) |
| 157 { | 157 { |
| 158 ASSERT(m_options.crossOriginRequestPolicy == UseAccessControl); | 158 ASSERT(m_options.crossOriginRequestPolicy == UseAccessControl); |
| 159 | 159 |
| 160 // Cross-origin requests are only allowed certain registered schemes. | 160 // Cross-origin requests are only allowed certain registered schemes. |
| 161 // We would catch this when checking response headers later, but there | 161 // We would catch this when checking response headers later, but there |
| 162 // is no reason to send a request, preflighted or not, that's guaranteed | 162 // is no reason to send a request, preflighted or not, that's guaranteed |
| 163 // to be denied. | 163 // to be denied. |
| 164 if (!SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(request.url().protoco
l())) { | 164 if (!SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(request.url().protoco
l())) { |
| 165 m_client->didFailAccessControlCheck(ResourceError(errorDomainBlinkIntern
al, 0, request.url().string(), "Cross origin requests are only supported for pro
tocol schemes: " + SchemeRegistry::listOfCORSEnabledURLSchemes() + ".")); | 165 handlePreflightFailure(request.url().string(), "Cross origin requests ar
e only supported for protocol schemes: " + SchemeRegistry::listOfCORSEnabledURLS
chemes() + "."); |
| 166 return; | 166 return; |
| 167 } | 167 } |
| 168 | 168 |
| 169 // We use isSimpleOrForbiddenRequest() here since |request| may have been | 169 // We use isSimpleOrForbiddenRequest() here since |request| may have been |
| 170 // modified in the process of loading (not from the user's input). For | 170 // modified in the process of loading (not from the user's input). For |
| 171 // example, referrer. We need to accept them. For security, we must reject | 171 // example, referrer. We need to accept them. For security, we must reject |
| 172 // forbidden headers/methods at the point we accept user's input. Not here. | 172 // forbidden headers/methods at the point we accept user's input. Not here. |
| 173 if ((m_options.preflightPolicy == ConsiderPreflight && FetchUtils::isSimpleO
rForbiddenRequest(request.httpMethod(), request.httpHeaderFields())) || m_option
s.preflightPolicy == PreventPreflight) { | 173 if ((m_options.preflightPolicy == ConsiderPreflight && FetchUtils::isSimpleO
rForbiddenRequest(request.httpMethod(), request.httpHeaderFields())) || m_option
s.preflightPolicy == PreventPreflight) { |
| 174 ResourceRequest crossOriginRequest(request); | 174 ResourceRequest crossOriginRequest(request); |
| 175 ResourceLoaderOptions crossOriginOptions(m_resourceLoaderOptions); | 175 ResourceLoaderOptions crossOriginOptions(m_resourceLoaderOptions); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 request.clearHTTPReferrer(); | 328 request.clearHTTPReferrer(); |
| 329 request.clearHTTPOrigin(); | 329 request.clearHTTPOrigin(); |
| 330 request.clearHTTPUserAgent(); | 330 request.clearHTTPUserAgent(); |
| 331 // Add any CORS simple request headers which we previously saved fro
m the original request. | 331 // Add any CORS simple request headers which we previously saved fro
m the original request. |
| 332 for (const auto& header : m_simpleRequestHeaders) | 332 for (const auto& header : m_simpleRequestHeaders) |
| 333 request.setHTTPHeaderField(header.key, header.value); | 333 request.setHTTPHeaderField(header.key, header.value); |
| 334 makeCrossOriginAccessRequest(request); | 334 makeCrossOriginAccessRequest(request); |
| 335 return; | 335 return; |
| 336 } | 336 } |
| 337 | 337 |
| 338 ResourceError error(errorDomainBlinkInternal, 0, redirectResponse.url().
string(), accessControlErrorDescription); | 338 handlePreflightFailure(redirectResponse.url().string(), accessControlErr
orDescription); |
| 339 m_client->didFailAccessControlCheck(error); | |
| 340 } else { | 339 } else { |
| 341 m_client->didFailRedirectCheck(); | 340 m_client->didFailRedirectCheck(); |
| 342 } | 341 } |
| 343 | 342 |
| 344 clearResource(); | 343 clearResource(); |
| 345 request = ResourceRequest(); | 344 request = ResourceRequest(); |
| 346 | 345 |
| 347 m_requestStartedSeconds = 0.0; | 346 m_requestStartedSeconds = 0.0; |
| 348 } | 347 } |
| 349 | 348 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 m_client->didReceiveResponse(identifier, response, handle); | 428 m_client->didReceiveResponse(identifier, response, handle); |
| 430 return; | 429 return; |
| 431 } | 430 } |
| 432 | 431 |
| 433 ASSERT(!m_fallbackRequestForServiceWorker); | 432 ASSERT(!m_fallbackRequestForServiceWorker); |
| 434 | 433 |
| 435 if (!m_sameOriginRequest && m_options.crossOriginRequestPolicy == UseAccessC
ontrol) { | 434 if (!m_sameOriginRequest && m_options.crossOriginRequestPolicy == UseAccessC
ontrol) { |
| 436 String accessControlErrorDescription; | 435 String accessControlErrorDescription; |
| 437 if (!passesAccessControlCheck(&m_document, response, effectiveAllowCrede
ntials(), securityOrigin(), accessControlErrorDescription)) { | 436 if (!passesAccessControlCheck(&m_document, response, effectiveAllowCrede
ntials(), securityOrigin(), accessControlErrorDescription)) { |
| 438 reportResponseReceived(identifier, response); | 437 reportResponseReceived(identifier, response); |
| 439 m_client->didFailAccessControlCheck(ResourceError(errorDomainBlinkIn
ternal, 0, response.url().string(), accessControlErrorDescription)); | 438 handlePreflightFailure(response.url().string(), accessControlErrorDe
scription); |
| 440 return; | 439 return; |
| 441 } | 440 } |
| 442 } | 441 } |
| 443 | 442 |
| 444 m_client->didReceiveResponse(identifier, response, handle); | 443 m_client->didReceiveResponse(identifier, response, handle); |
| 445 } | 444 } |
| 446 | 445 |
| 447 void DocumentThreadableLoader::dataReceived(Resource* resource, const char* data
, unsigned dataLength) | 446 void DocumentThreadableLoader::dataReceived(Resource* resource, const char* data
, unsigned dataLength) |
| 448 { | 447 { |
| 449 ASSERT_UNUSED(resource, resource == this->resource()); | 448 ASSERT_UNUSED(resource, resource == this->resource()); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 loadRequest(*actualRequest, *actualOptions); | 526 loadRequest(*actualRequest, *actualOptions); |
| 528 } | 527 } |
| 529 | 528 |
| 530 void DocumentThreadableLoader::handlePreflightFailure(const String& url, const S
tring& errorDescription) | 529 void DocumentThreadableLoader::handlePreflightFailure(const String& url, const S
tring& errorDescription) |
| 531 { | 530 { |
| 532 ResourceError error(errorDomainBlinkInternal, 0, url, errorDescription); | 531 ResourceError error(errorDomainBlinkInternal, 0, url, errorDescription); |
| 533 | 532 |
| 534 // Prevent handleSuccessfulFinish() from bypassing access check. | 533 // Prevent handleSuccessfulFinish() from bypassing access check. |
| 535 m_actualRequest = nullptr; | 534 m_actualRequest = nullptr; |
| 536 | 535 |
| 536 // Do not call didFailAccessControlCheck() directly from other places in |
| 537 // DocumentThreadableLoader. |
| 538 // Call handlePreflightFailure() to prevent m_client's handlers from |
| 539 // being called after didFailAccessControlCheck(). |
| 540 |
| 537 // FIXME: Should prevent timeout from being overridden after preflight failu
re, without | 541 // FIXME: Should prevent timeout from being overridden after preflight failu
re, without |
| 538 // resetting m_requestStartedSeconds to 0.0 | 542 // resetting m_requestStartedSeconds to 0.0 |
| 539 m_client->didFailAccessControlCheck(error); | 543 m_client->didFailAccessControlCheck(error); |
| 544 |
| 545 // Prevent m_client's handlers from being called later. |
| 546 clearResource(); |
| 540 } | 547 } |
| 541 | 548 |
| 542 void DocumentThreadableLoader::loadRequest(const ResourceRequest& request, Resou
rceLoaderOptions resourceLoaderOptions) | 549 void DocumentThreadableLoader::loadRequest(const ResourceRequest& request, Resou
rceLoaderOptions resourceLoaderOptions) |
| 543 { | 550 { |
| 544 // Any credential should have been removed from the cross-site requests. | 551 // Any credential should have been removed from the cross-site requests. |
| 545 const KURL& requestURL = request.url(); | 552 const KURL& requestURL = request.url(); |
| 546 ASSERT(m_sameOriginRequest || requestURL.user().isEmpty()); | 553 ASSERT(m_sameOriginRequest || requestURL.user().isEmpty()); |
| 547 ASSERT(m_sameOriginRequest || requestURL.pass().isEmpty()); | 554 ASSERT(m_sameOriginRequest || requestURL.pass().isEmpty()); |
| 548 | 555 |
| 549 // Update resourceLoaderOptions with enforced values. | 556 // Update resourceLoaderOptions with enforced values. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 return DoNotAllowStoredCredentials; | 639 return DoNotAllowStoredCredentials; |
| 633 return m_resourceLoaderOptions.allowCredentials; | 640 return m_resourceLoaderOptions.allowCredentials; |
| 634 } | 641 } |
| 635 | 642 |
| 636 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const | 643 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const |
| 637 { | 644 { |
| 638 return m_securityOrigin ? m_securityOrigin.get() : m_document.securityOrigin
(); | 645 return m_securityOrigin ? m_securityOrigin.get() : m_document.securityOrigin
(); |
| 639 } | 646 } |
| 640 | 647 |
| 641 } // namespace blink | 648 } // namespace blink |
| OLD | NEW |