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

Side by Side Diff: third_party/WebKit/Source/core/loader/FrameFetchContext.cpp

Issue 2022083002: Move 'frame-src' CSP checks into FrameFetchContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: yoav Created 4 years, 6 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) 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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 case Resource::XSLStyleSheet: 507 case Resource::XSLStyleSheet:
508 ASSERT(RuntimeEnabledFeatures::xsltEnabled()); 508 ASSERT(RuntimeEnabledFeatures::xsltEnabled());
509 case Resource::SVGDocument: 509 case Resource::SVGDocument:
510 if (!securityOrigin->canRequest(url)) { 510 if (!securityOrigin->canRequest(url)) {
511 printAccessDeniedMessage(url); 511 printAccessDeniedMessage(url);
512 return ResourceRequestBlockedReasonOrigin; 512 return ResourceRequestBlockedReasonOrigin;
513 } 513 }
514 break; 514 break;
515 } 515 }
516 516
517 // FIXME: Convert this to check the isolated world's Content Security Policy once webkit.org/b/104520 is solved. 517 if (contentSecurityPolicyBlocksRequest(type, resourceRequest, url, options, forPreload, redirectStatus))
Mike West 2016/06/02 13:39:30 Does this extraction make you happier, Yoav? :)
Yoav Weiss 2016/06/02 14:13:37 way happier :D
518 bool shouldBypassMainWorldCSP = frame()->script().shouldBypassMainWorldCSP() || options.contentSecurityPolicyOption == DoNotCheckContentSecurityPolicy; 518 return ResourceRequestBlockedReasonCSP;
519
520 // Don't send CSP messages for preloads, we might never actually display tho se items.
521 ContentSecurityPolicy::ReportingStatus cspReporting = forPreload ?
522 ContentSecurityPolicy::SuppressReport : ContentSecurityPolicy::SendRepor t;
523
524 if (m_document) {
525 DCHECK(m_document->contentSecurityPolicy());
526 if (!shouldBypassMainWorldCSP && !m_document->contentSecurityPolicy()->a llowRequest(resourceRequest.requestContext(), url, redirectStatus, cspReporting) )
527 return ResourceRequestBlockedReasonCSP;
528 }
529 519
530 if (type == Resource::Script || type == Resource::ImportResource) { 520 if (type == Resource::Script || type == Resource::ImportResource) {
531 ASSERT(frame()); 521 ASSERT(frame());
532 if (!frame()->loader().client()->allowScriptFromSource(!frame()->setting s() || frame()->settings()->scriptEnabled(), url)) { 522 if (!frame()->loader().client()->allowScriptFromSource(!frame()->setting s() || frame()->settings()->scriptEnabled(), url)) {
533 frame()->loader().client()->didNotAllowScript(); 523 frame()->loader().client()->didNotAllowScript();
534 // TODO(estark): Use a different ResourceRequestBlockedReason 524 // TODO(estark): Use a different ResourceRequestBlockedReason
535 // here, since this check has nothing to do with 525 // here, since this check has nothing to do with
536 // CSP. https://crbug.com/600795 526 // CSP. https://crbug.com/600795
537 return ResourceRequestBlockedReasonCSP; 527 return ResourceRequestBlockedReasonCSP;
538 } 528 }
(...skipping 23 matching lines...) Expand all
562 // folks block mixed content with a CSP policy, they don't get a warning. 552 // folks block mixed content with a CSP policy, they don't get a warning.
563 // They'll still get a warning in the console about CSP blocking the load. 553 // They'll still get a warning in the console about CSP blocking the load.
564 MixedContentChecker::ReportingStatus mixedContentReporting = forPreload ? 554 MixedContentChecker::ReportingStatus mixedContentReporting = forPreload ?
565 MixedContentChecker::SuppressReport : MixedContentChecker::SendReport; 555 MixedContentChecker::SuppressReport : MixedContentChecker::SendReport;
566 if (MixedContentChecker::shouldBlockFetch(frame(), resourceRequest, url, mix edContentReporting)) 556 if (MixedContentChecker::shouldBlockFetch(frame(), resourceRequest, url, mix edContentReporting))
567 return ResourceRequestBlockedReasonMixedContent; 557 return ResourceRequestBlockedReasonMixedContent;
568 558
569 return ResourceRequestBlockedReasonNone; 559 return ResourceRequestBlockedReasonNone;
570 } 560 }
571 561
562 bool FrameFetchContext::contentSecurityPolicyBlocksRequest(Resource::Type type, const ResourceRequest& resourceRequest, const KURL& url, const ResourceLoaderOpt ions& options, bool forPreload, ResourceRequest::RedirectStatus redirectStatus) const
563 {
564 // FIXME: Convert this to check the isolated world's Content Security Policy once webkit.org/b/104520 is solved.
565 if (!frame()->script().shouldBypassMainWorldCSP() && options.contentSecurity PolicyOption == CheckContentSecurityPolicy) {
566 // Don't send CSP messages for preloads, we might never actually display those items.
567 ContentSecurityPolicy::ReportingStatus cspReporting = forPreload ?
568 ContentSecurityPolicy::SuppressReport : ContentSecurityPolicy::SendR eport;
569 if (m_document) {
570 DCHECK(m_document->contentSecurityPolicy());
571 if (!m_document->contentSecurityPolicy()->allowRequest(resourceReque st.requestContext(), url, redirectStatus, cspReporting))
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 (so |csp| will be nullptr). We instead need to grab the frame 's
alexmos 2016/06/02 22:21:07 nit: I don't see |csp| defined anywhere in this fu
Mike West 2016/06/06 08:40:10 Done. Too much refactoring. :)
576 // parent's policy in order to perform 'frame-src' checks:
577 if (Frame* parentFrame = frame()->tree().parent()) {
dcheng 2016/06/02 21:48:56 How does CSP inheritance work? Is it always strict
Mike West 2016/06/06 08:40:10 In this case, I think pulling the policy from the
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
572 bool FrameFetchContext::isControlledByServiceWorker() const 594 bool FrameFetchContext::isControlledByServiceWorker() const
573 { 595 {
574 ASSERT(m_documentLoader || frame()->loader().documentLoader()); 596 ASSERT(m_documentLoader || frame()->loader().documentLoader());
575 if (m_documentLoader) 597 if (m_documentLoader)
576 return frame()->loader().client()->isControlledByServiceWorker(*m_docume ntLoader); 598 return frame()->loader().client()->isControlledByServiceWorker(*m_docume ntLoader);
577 // m_documentLoader is null while loading resources from an HTML import. 599 // m_documentLoader is null while loading resources from an HTML import.
578 // 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
579 // is determined by the document loader of the frame. 601 // is determined by the document loader of the frame.
580 return frame()->loader().client()->isControlledByServiceWorker(*frame()->loa der().documentLoader()); 602 return frame()->loader().client()->isControlledByServiceWorker(*frame()->loa der().documentLoader());
581 } 603 }
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 } 823 }
802 824
803 DEFINE_TRACE(FrameFetchContext) 825 DEFINE_TRACE(FrameFetchContext)
804 { 826 {
805 visitor->trace(m_document); 827 visitor->trace(m_document);
806 visitor->trace(m_documentLoader); 828 visitor->trace(m_documentLoader);
807 FetchContext::trace(visitor); 829 FetchContext::trace(visitor);
808 } 830 }
809 831
810 } // namespace blink 832 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698