| 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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 return false; | 587 return false; |
| 588 } | 588 } |
| 589 return true; | 589 return true; |
| 590 } | 590 } |
| 591 | 591 |
| 592 bool FrameFetchContext::allowResponse( | 592 bool FrameFetchContext::allowResponse( |
| 593 Resource::Type type, | 593 Resource::Type type, |
| 594 const ResourceRequest& resourceRequest, | 594 const ResourceRequest& resourceRequest, |
| 595 const KURL& url, | 595 const KURL& url, |
| 596 const ResourceLoaderOptions& options) const { | 596 const ResourceLoaderOptions& options) const { |
| 597 // canRequestInternal only checks enforced policies: check report-only here |
| 598 // to ensure violations are sent. |
| 599 checkCSPForRequest(resourceRequest, url, options, false, |
| 600 RedirectStatus::FollowedRedirect, |
| 601 ContentSecurityPolicyHeaderTypeReport); |
| 597 ResourceRequestBlockedReason reason = | 602 ResourceRequestBlockedReason reason = |
| 598 canRequestInternal(type, resourceRequest, url, options, false, | 603 canRequestInternal(type, resourceRequest, url, options, false, |
| 599 FetchRequest::UseDefaultOriginRestrictionForType, | 604 FetchRequest::UseDefaultOriginRestrictionForType, |
| 600 RedirectStatus::FollowedRedirect); | 605 RedirectStatus::FollowedRedirect); |
| 601 if (reason != ResourceRequestBlockedReasonNone) { | 606 if (reason != ResourceRequestBlockedReasonNone) { |
| 602 InspectorInstrumentation::didBlockRequest(frame(), resourceRequest, | 607 InspectorInstrumentation::didBlockRequest(frame(), resourceRequest, |
| 603 masterDocumentLoader(), | 608 masterDocumentLoader(), |
| 604 options.initiatorInfo, reason); | 609 options.initiatorInfo, reason); |
| 605 return false; | 610 return false; |
| 606 } | 611 } |
| 607 return true; | 612 return true; |
| 608 } | 613 } |
| 609 | 614 |
| 615 ResourceRequestBlockedReason FrameFetchContext::checkCSPForRequest( |
| 616 const ResourceRequest& resourceRequest, |
| 617 const KURL& url, |
| 618 const ResourceLoaderOptions& options, |
| 619 bool forPreload, |
| 620 ResourceRequest::RedirectStatus redirectStatus, |
| 621 ContentSecurityPolicyHeaderType headerType) const { |
| 622 if (frame()->script().shouldBypassMainWorldCSP() || |
| 623 options.contentSecurityPolicyOption == DoNotCheckContentSecurityPolicy) { |
| 624 return ResourceRequestBlockedReasonNone; |
| 625 } |
| 626 |
| 627 // Don't send CSP messages for preloads, we might never actually display those |
| 628 // items. |
| 629 ContentSecurityPolicy::ReportingStatus cspReporting = |
| 630 forPreload ? ContentSecurityPolicy::SuppressReport |
| 631 : ContentSecurityPolicy::SendReport; |
| 632 |
| 633 if (m_document) { |
| 634 DCHECK(m_document->contentSecurityPolicy()); |
| 635 if (!m_document->contentSecurityPolicy()->allowRequest( |
| 636 resourceRequest.requestContext(), url, |
| 637 options.contentSecurityPolicyNonce, options.integrityMetadata, |
| 638 options.parserDisposition, redirectStatus, cspReporting, |
| 639 headerType)) |
| 640 return ResourceRequestBlockedReasonCSP; |
| 641 } |
| 642 return ResourceRequestBlockedReasonNone; |
| 643 } |
| 644 |
| 610 ResourceRequestBlockedReason FrameFetchContext::canRequestInternal( | 645 ResourceRequestBlockedReason FrameFetchContext::canRequestInternal( |
| 611 Resource::Type type, | 646 Resource::Type type, |
| 612 const ResourceRequest& resourceRequest, | 647 const ResourceRequest& resourceRequest, |
| 613 const KURL& url, | 648 const KURL& url, |
| 614 const ResourceLoaderOptions& options, | 649 const ResourceLoaderOptions& options, |
| 615 bool forPreload, | 650 bool forPreload, |
| 616 FetchRequest::OriginRestriction originRestriction, | 651 FetchRequest::OriginRestriction originRestriction, |
| 617 ResourceRequest::RedirectStatus redirectStatus) const { | 652 ResourceRequest::RedirectStatus redirectStatus) const { |
| 618 if (InspectorInstrumentation::shouldBlockRequest(frame(), resourceRequest)) | 653 if (InspectorInstrumentation::shouldBlockRequest(frame(), resourceRequest)) |
| 619 return ResourceRequestBlockedReasonInspector; | 654 return ResourceRequestBlockedReasonInspector; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 case Resource::XSLStyleSheet: | 692 case Resource::XSLStyleSheet: |
| 658 DCHECK(RuntimeEnabledFeatures::xsltEnabled()); | 693 DCHECK(RuntimeEnabledFeatures::xsltEnabled()); |
| 659 case Resource::SVGDocument: | 694 case Resource::SVGDocument: |
| 660 if (!securityOrigin->canRequest(url)) { | 695 if (!securityOrigin->canRequest(url)) { |
| 661 printAccessDeniedMessage(url); | 696 printAccessDeniedMessage(url); |
| 662 return ResourceRequestBlockedReasonOrigin; | 697 return ResourceRequestBlockedReasonOrigin; |
| 663 } | 698 } |
| 664 break; | 699 break; |
| 665 } | 700 } |
| 666 | 701 |
| 667 // FIXME: Convert this to check the isolated world's Content Security Policy | 702 // We check the 'report-only' headers before upgrading the request (in |
| 668 // once webkit.org/b/104520 is solved. | 703 // 'modifyRequestForCSP'). We check the enforced headers here to ensure we |
| 669 bool shouldBypassMainWorldCSP = | 704 // block things we ought to block. |
| 670 frame()->script().shouldBypassMainWorldCSP() || | 705 if (checkCSPForRequest(resourceRequest, url, options, forPreload, |
| 671 options.contentSecurityPolicyOption == DoNotCheckContentSecurityPolicy; | 706 redirectStatus, |
| 672 | 707 ContentSecurityPolicyHeaderTypeEnforce) == |
| 673 // Don't send CSP messages for preloads, we might never actually display those | 708 ResourceRequestBlockedReasonCSP) { |
| 674 // items. | 709 return ResourceRequestBlockedReasonCSP; |
| 675 ContentSecurityPolicy::ReportingStatus cspReporting = | |
| 676 forPreload ? ContentSecurityPolicy::SuppressReport | |
| 677 : ContentSecurityPolicy::SendReport; | |
| 678 | |
| 679 if (m_document) { | |
| 680 DCHECK(m_document->contentSecurityPolicy()); | |
| 681 if (!shouldBypassMainWorldCSP && | |
| 682 !m_document->contentSecurityPolicy()->allowRequest( | |
| 683 resourceRequest.requestContext(), url, | |
| 684 options.contentSecurityPolicyNonce, options.integrityMetadata, | |
| 685 options.parserDisposition, redirectStatus, cspReporting)) | |
| 686 return ResourceRequestBlockedReasonCSP; | |
| 687 } | 710 } |
| 688 | 711 |
| 689 if (type == Resource::Script || type == Resource::ImportResource) { | 712 if (type == Resource::Script || type == Resource::ImportResource) { |
| 690 DCHECK(frame()); | 713 DCHECK(frame()); |
| 691 if (!frame()->loader().client()->allowScriptFromSource( | 714 if (!frame()->loader().client()->allowScriptFromSource( |
| 692 !frame()->settings() || frame()->settings()->scriptEnabled(), | 715 !frame()->settings() || frame()->settings()->scriptEnabled(), |
| 693 url)) { | 716 url)) { |
| 694 frame()->loader().client()->didNotAllowScript(); | 717 frame()->loader().client()->didNotAllowScript(); |
| 695 // TODO(estark): Use a different ResourceRequestBlockedReason here, since | 718 // TODO(estark): Use a different ResourceRequestBlockedReason here, since |
| 696 // this check has nothing to do with CSP. https://crbug.com/600795 | 719 // this check has nothing to do with CSP. https://crbug.com/600795 |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 response); | 1029 response); |
| 1007 } | 1030 } |
| 1008 | 1031 |
| 1009 DEFINE_TRACE(FrameFetchContext) { | 1032 DEFINE_TRACE(FrameFetchContext) { |
| 1010 visitor->trace(m_document); | 1033 visitor->trace(m_document); |
| 1011 visitor->trace(m_documentLoader); | 1034 visitor->trace(m_documentLoader); |
| 1012 FetchContext::trace(visitor); | 1035 FetchContext::trace(visitor); |
| 1013 } | 1036 } |
| 1014 | 1037 |
| 1015 } // namespace blink | 1038 } // namespace blink |
| OLD | NEW |