| 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 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 | 477 |
| 478 // Don't send CSP messages for preloads, we might never actually display tho
se items. | 478 // Don't send CSP messages for preloads, we might never actually display tho
se items. |
| 479 ContentSecurityPolicy::ReportingStatus cspReporting = forPreload ? | 479 ContentSecurityPolicy::ReportingStatus cspReporting = forPreload ? |
| 480 ContentSecurityPolicy::SuppressReport : ContentSecurityPolicy::SendRepor
t; | 480 ContentSecurityPolicy::SuppressReport : ContentSecurityPolicy::SendRepor
t; |
| 481 | 481 |
| 482 // m_document can be null, but not in any of the cases where csp is actually
used below. | 482 // m_document can be null, but not in any of the cases where csp is actually
used below. |
| 483 // ImageResourceTest.MultipartImage crashes w/o the m_document null check. | 483 // ImageResourceTest.MultipartImage crashes w/o the m_document null check. |
| 484 // I believe it's the Resource::Raw case. | 484 // I believe it's the Resource::Raw case. |
| 485 const ContentSecurityPolicy* csp = m_document ? m_document->contentSecurityP
olicy() : nullptr; | 485 const ContentSecurityPolicy* csp = m_document ? m_document->contentSecurityP
olicy() : nullptr; |
| 486 | 486 |
| 487 // TODO(mkwst): This would be cleaner if moved this switch into an allowFrom
Source() | 487 if (csp) { |
| 488 // helper on this object which took a Resource::Type, then this block would | 488 if (!shouldBypassMainWorldCSP && !csp->allowRequest(resourceRequest.requ
estContext(), url, redirectStatus, cspReporting)) |
| 489 // collapse to about 10 lines for handling Raw and Script special cases. | |
| 490 switch (type) { | |
| 491 case Resource::XSLStyleSheet: | |
| 492 ASSERT(RuntimeEnabledFeatures::xsltEnabled()); | |
| 493 ASSERT(ContentSecurityPolicy::isScriptResource(resourceRequest)); | |
| 494 ASSERT(csp); | |
| 495 if (!shouldBypassMainWorldCSP && !csp->allowScriptFromSource(url, redire
ctStatus, cspReporting)) | |
| 496 return ResourceRequestBlockedReasonCSP; | 489 return ResourceRequestBlockedReasonCSP; |
| 497 break; | 490 } |
| 498 case Resource::Script: | 491 |
| 499 case Resource::ImportResource: | 492 if (type == Resource::Script || type == Resource::ImportResource) { |
| 500 ASSERT(ContentSecurityPolicy::isScriptResource(resourceRequest)); | |
| 501 ASSERT(csp); | |
| 502 if (!shouldBypassMainWorldCSP && !csp->allowScriptFromSource(url, redire
ctStatus, cspReporting)) | |
| 503 return ResourceRequestBlockedReasonCSP; | |
| 504 ASSERT(frame()); | 493 ASSERT(frame()); |
| 505 if (!frame()->loader().client()->allowScriptFromSource(!frame()->setting
s() || frame()->settings()->scriptEnabled(), url)) { | 494 if (!frame()->loader().client()->allowScriptFromSource(!frame()->setting
s() || frame()->settings()->scriptEnabled(), url)) { |
| 506 frame()->loader().client()->didNotAllowScript(); | 495 frame()->loader().client()->didNotAllowScript(); |
| 496 // TODO(estark): Use a different ResourceRequestBlockedReason |
| 497 // here, since this check has nothing to do with |
| 498 // CSP. https://crbug.com/600795 |
| 507 return ResourceRequestBlockedReasonCSP; | 499 return ResourceRequestBlockedReasonCSP; |
| 508 } | 500 } |
| 509 break; | 501 } else if (type == Resource::Media || type == Resource::TextTrack) { |
| 510 case Resource::CSSStyleSheet: | 502 ASSERT(frame()); |
| 511 ASSERT(ContentSecurityPolicy::isStyleResource(resourceRequest)); | |
| 512 ASSERT(csp); | |
| 513 if (!shouldBypassMainWorldCSP && !csp->allowStyleFromSource(url, redirec
tStatus, cspReporting)) | |
| 514 return ResourceRequestBlockedReasonCSP; | |
| 515 break; | |
| 516 case Resource::SVGDocument: | |
| 517 case Resource::Image: | |
| 518 ASSERT(ContentSecurityPolicy::isImageResource(resourceRequest)); | |
| 519 ASSERT(csp); | |
| 520 if (!shouldBypassMainWorldCSP && !csp->allowImageFromSource(url, redirec
tStatus, cspReporting)) | |
| 521 return ResourceRequestBlockedReasonCSP; | |
| 522 break; | |
| 523 case Resource::Font: { | |
| 524 ASSERT(ContentSecurityPolicy::isFontResource(resourceRequest)); | |
| 525 ASSERT(csp); | |
| 526 if (!shouldBypassMainWorldCSP && !csp->allowFontFromSource(url, redirect
Status, cspReporting)) | |
| 527 return ResourceRequestBlockedReasonCSP; | |
| 528 break; | |
| 529 } | |
| 530 case Resource::LinkPreload: | |
| 531 ASSERT(csp); | |
| 532 if (!shouldBypassMainWorldCSP && !csp->allowConnectToSource(url, redirec
tStatus, cspReporting)) | |
| 533 return ResourceRequestBlockedReasonCSP; | |
| 534 break; | |
| 535 case Resource::MainResource: | |
| 536 case Resource::Raw: | |
| 537 case Resource::LinkPrefetch: | |
| 538 case Resource::Manifest: | |
| 539 break; | |
| 540 case Resource::Media: | |
| 541 case Resource::TextTrack: | |
| 542 ASSERT(ContentSecurityPolicy::isMediaResource(resourceRequest)); | |
| 543 ASSERT(csp); | |
| 544 if (!shouldBypassMainWorldCSP && !csp->allowMediaFromSource(url, redirec
tStatus, cspReporting)) | |
| 545 return ResourceRequestBlockedReasonCSP; | |
| 546 | |
| 547 if (!frame()->loader().client()->allowMedia(url)) | 503 if (!frame()->loader().client()->allowMedia(url)) |
| 548 return ResourceRequestBlockedReasonOther; | 504 return ResourceRequestBlockedReasonOther; |
| 549 break; | |
| 550 } | 505 } |
| 551 | 506 |
| 552 // SVG Images have unique security rules that prevent all subresource reques
ts | 507 // SVG Images have unique security rules that prevent all subresource reques
ts |
| 553 // except for data urls. | 508 // except for data urls. |
| 554 if (type != Resource::MainResource && frame()->chromeClient().isSVGImageChro
meClient() && !url.protocolIsData()) | 509 if (type != Resource::MainResource && frame()->chromeClient().isSVGImageChro
meClient() && !url.protocolIsData()) |
| 555 return ResourceRequestBlockedReasonOrigin; | 510 return ResourceRequestBlockedReasonOrigin; |
| 556 | 511 |
| 557 // FIXME: Once we use RequestContext for CSP (http://crbug.com/390497), remo
ve this extra check. | |
| 558 if (resourceRequest.requestContext() == WebURLRequest::RequestContextManifes
t) { | |
| 559 ASSERT(csp); | |
| 560 if (!shouldBypassMainWorldCSP && !csp->allowManifestFromSource(url, redi
rectStatus, cspReporting)) | |
| 561 return ResourceRequestBlockedReasonCSP; | |
| 562 } | |
| 563 | |
| 564 // Measure the number of legacy URL schemes ('ftp://') and the number of emb
edded-credential | 512 // Measure the number of legacy URL schemes ('ftp://') and the number of emb
edded-credential |
| 565 // ('http://user:password@...') resources embedded as subresources. in the h
opes that we can | 513 // ('http://user:password@...') resources embedded as subresources. in the h
opes that we can |
| 566 // block them at some point in the future. | 514 // block them at some point in the future. |
| 567 if (resourceRequest.frameType() != WebURLRequest::FrameTypeTopLevel) { | 515 if (resourceRequest.frameType() != WebURLRequest::FrameTypeTopLevel) { |
| 568 ASSERT(frame()->document()); | 516 ASSERT(frame()->document()); |
| 569 if (SchemeRegistry::shouldTreatURLSchemeAsLegacy(url.protocol()) && !Sch
emeRegistry::shouldTreatURLSchemeAsLegacy(frame()->document()->getSecurityOrigin
()->protocol())) | 517 if (SchemeRegistry::shouldTreatURLSchemeAsLegacy(url.protocol()) && !Sch
emeRegistry::shouldTreatURLSchemeAsLegacy(frame()->document()->getSecurityOrigin
()->protocol())) |
| 570 UseCounter::count(frame()->document(), UseCounter::LegacyProtocolEmb
eddedAsSubresource); | 518 UseCounter::count(frame()->document(), UseCounter::LegacyProtocolEmb
eddedAsSubresource); |
| 571 if (!url.user().isEmpty() || !url.pass().isEmpty()) | 519 if (!url.user().isEmpty() || !url.pass().isEmpty()) |
| 572 UseCounter::count(frame()->document(), UseCounter::RequestedSubresou
rceWithEmbeddedCredentials); | 520 UseCounter::count(frame()->document(), UseCounter::RequestedSubresou
rceWithEmbeddedCredentials); |
| 573 } | 521 } |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 } | 769 } |
| 822 | 770 |
| 823 DEFINE_TRACE(FrameFetchContext) | 771 DEFINE_TRACE(FrameFetchContext) |
| 824 { | 772 { |
| 825 visitor->trace(m_document); | 773 visitor->trace(m_document); |
| 826 visitor->trace(m_documentLoader); | 774 visitor->trace(m_documentLoader); |
| 827 FetchContext::trace(visitor); | 775 FetchContext::trace(visitor); |
| 828 } | 776 } |
| 829 | 777 |
| 830 } // namespace blink | 778 } // namespace blink |
| OLD | NEW |