OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 case Resource::XSLStyleSheet: | 508 case Resource::XSLStyleSheet: |
509 ASSERT(RuntimeEnabledFeatures::xsltEnabled()); | 509 ASSERT(RuntimeEnabledFeatures::xsltEnabled()); |
510 case Resource::SVGDocument: | 510 case Resource::SVGDocument: |
511 if (!securityOrigin->canRequest(url)) { | 511 if (!securityOrigin->canRequest(url)) { |
512 printAccessDeniedMessage(url); | 512 printAccessDeniedMessage(url); |
513 return ResourceRequestBlockedReasonOrigin; | 513 return ResourceRequestBlockedReasonOrigin; |
514 } | 514 } |
515 break; | 515 break; |
516 } | 516 } |
517 | 517 |
518 // FIXME: Convert this to check the isolated world's Content Security Policy
once webkit.org/b/104520 is solved. | 518 if (contentSecurityPolicyBlocksRequest(type, resourceRequest, url, options,
forPreload, redirectStatus)) |
519 bool shouldBypassMainWorldCSP = frame()->script().shouldBypassMainWorldCSP()
|| options.contentSecurityPolicyOption == DoNotCheckContentSecurityPolicy; | 519 return ResourceRequestBlockedReasonCSP; |
520 | |
521 // Don't send CSP messages for preloads, we might never actually display tho
se items. | |
522 ContentSecurityPolicy::ReportingStatus cspReporting = forPreload ? | |
523 ContentSecurityPolicy::SuppressReport : ContentSecurityPolicy::SendRepor
t; | |
524 | |
525 if (m_document) { | |
526 DCHECK(m_document->contentSecurityPolicy()); | |
527 if (!shouldBypassMainWorldCSP && !m_document->contentSecurityPolicy()->a
llowRequest(resourceRequest.requestContext(), url, options.contentSecurityPolicy
Nonce, redirectStatus, cspReporting)) | |
528 return ResourceRequestBlockedReasonCSP; | |
529 } | |
530 | 520 |
531 if (type == Resource::Script || type == Resource::ImportResource) { | 521 if (type == Resource::Script || type == Resource::ImportResource) { |
532 ASSERT(frame()); | 522 ASSERT(frame()); |
533 if (!frame()->loader().client()->allowScriptFromSource(!frame()->setting
s() || frame()->settings()->scriptEnabled(), url)) { | 523 if (!frame()->loader().client()->allowScriptFromSource(!frame()->setting
s() || frame()->settings()->scriptEnabled(), url)) { |
534 frame()->loader().client()->didNotAllowScript(); | 524 frame()->loader().client()->didNotAllowScript(); |
535 // TODO(estark): Use a different ResourceRequestBlockedReason | 525 // TODO(estark): Use a different ResourceRequestBlockedReason |
536 // here, since this check has nothing to do with | 526 // here, since this check has nothing to do with |
537 // CSP. https://crbug.com/600795 | 527 // CSP. https://crbug.com/600795 |
538 return ResourceRequestBlockedReasonCSP; | 528 return ResourceRequestBlockedReasonCSP; |
539 } | 529 } |
(...skipping 23 matching lines...) Expand all Loading... |
563 // folks block mixed content with a CSP policy, they don't get a warning. | 553 // folks block mixed content with a CSP policy, they don't get a warning. |
564 // They'll still get a warning in the console about CSP blocking the load. | 554 // They'll still get a warning in the console about CSP blocking the load. |
565 MixedContentChecker::ReportingStatus mixedContentReporting = forPreload ? | 555 MixedContentChecker::ReportingStatus mixedContentReporting = forPreload ? |
566 MixedContentChecker::SuppressReport : MixedContentChecker::SendReport; | 556 MixedContentChecker::SuppressReport : MixedContentChecker::SendReport; |
567 if (MixedContentChecker::shouldBlockFetch(frame(), resourceRequest, url, mix
edContentReporting)) | 557 if (MixedContentChecker::shouldBlockFetch(frame(), resourceRequest, url, mix
edContentReporting)) |
568 return ResourceRequestBlockedReasonMixedContent; | 558 return ResourceRequestBlockedReasonMixedContent; |
569 | 559 |
570 return ResourceRequestBlockedReasonNone; | 560 return ResourceRequestBlockedReasonNone; |
571 } | 561 } |
572 | 562 |
| 563 bool FrameFetchContext::contentSecurityPolicyBlocksRequest(Resource::Type type,
const ResourceRequest& resourceRequest, const KURL& url, const ResourceLoaderOpt
ions& options, bool forPreload, ResourceRequest::RedirectStatus redirectStatus)
const |
| 564 { |
| 565 // FIXME: Convert this to check the isolated world's Content Security Policy
once webkit.org/b/104520 is solved. |
| 566 if (!frame()->script().shouldBypassMainWorldCSP() && options.contentSecurity
PolicyOption == CheckContentSecurityPolicy) { |
| 567 // Don't send CSP messages for preloads, we might never actually display
those items. |
| 568 ContentSecurityPolicy::ReportingStatus cspReporting = forPreload ? Conte
ntSecurityPolicy::SuppressReport : ContentSecurityPolicy::SendReport; |
| 569 if (m_document) { |
| 570 DCHECK(m_document->contentSecurityPolicy()); |
| 571 if (!m_document->contentSecurityPolicy()->allowRequest(resourceReque
st.requestContext(), url, options.contentSecurityPolicyNonce, redirectStatus, cs
pReporting)) |
| 572 return true; |
| 573 } else if (type == Resource::MainResource) { |
| 574 // When loading the main document of an iframe, we won't have a docu
ment |
| 575 // yet. We instead need to grab the frame's parent's policy in order
to |
| 576 // perform 'frame-src' checks: |
| 577 if (Frame* parentFrame = frame()->tree().parent()) { |
| 578 if (!parentFrame->securityContext()->contentSecurityPolicy()->al
lowChildFrameFromSource(url, redirectStatus, cspReporting)) { |
| 579 // TODO(mkwst): If we cancel the request after a redirect, w
e never instantiate |
| 580 // a document, and therefore don't inherit the loader's sand
box flags, or trigger |
| 581 // a load event. This is strange. |
| 582 if (redirectStatus == ResourceRequest::RedirectStatus::Follo
wedRedirect) { |
| 583 frame()->document()->enforceSandboxFlags(SandboxOrigin); |
| 584 frame()->owner()->dispatchLoad(); |
| 585 } |
| 586 return true; |
| 587 } |
| 588 } |
| 589 } |
| 590 } |
| 591 return false; |
| 592 } |
| 593 |
573 bool FrameFetchContext::isControlledByServiceWorker() const | 594 bool FrameFetchContext::isControlledByServiceWorker() const |
574 { | 595 { |
575 ASSERT(m_documentLoader || frame()->loader().documentLoader()); | 596 ASSERT(m_documentLoader || frame()->loader().documentLoader()); |
576 if (m_documentLoader) | 597 if (m_documentLoader) |
577 return frame()->loader().client()->isControlledByServiceWorker(*m_docume
ntLoader); | 598 return frame()->loader().client()->isControlledByServiceWorker(*m_docume
ntLoader); |
578 // m_documentLoader is null while loading resources from an HTML import. | 599 // m_documentLoader is null while loading resources from an HTML import. |
579 // In such cases whether the request is controlled by ServiceWorker or not | 600 // In such cases whether the request is controlled by ServiceWorker or not |
580 // is determined by the document loader of the frame. | 601 // is determined by the document loader of the frame. |
581 return frame()->loader().client()->isControlledByServiceWorker(*frame()->loa
der().documentLoader()); | 602 return frame()->loader().client()->isControlledByServiceWorker(*frame()->loa
der().documentLoader()); |
582 } | 603 } |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 } | 778 } |
758 | 779 |
759 DEFINE_TRACE(FrameFetchContext) | 780 DEFINE_TRACE(FrameFetchContext) |
760 { | 781 { |
761 visitor->trace(m_document); | 782 visitor->trace(m_document); |
762 visitor->trace(m_documentLoader); | 783 visitor->trace(m_documentLoader); |
763 FetchContext::trace(visitor); | 784 FetchContext::trace(visitor); |
764 } | 785 } |
765 | 786 |
766 } // namespace blink | 787 } // namespace blink |
OLD | NEW |