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

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

Issue 2053693002: WIP: Move 'Upgrade-Insecure-Requests' to the browser process. Base URL: https://chromium.googlesource.com/chromium/src.git@replicate
Patch Set: 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 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 UseCounter::count(frame()->document(), UseCounter::LegacyProtocolEmb eddedAsSubresource); 549 UseCounter::count(frame()->document(), UseCounter::LegacyProtocolEmb eddedAsSubresource);
550 if (!url.user().isEmpty() || !url.pass().isEmpty()) 550 if (!url.user().isEmpty() || !url.pass().isEmpty())
551 UseCounter::count(frame()->document(), UseCounter::RequestedSubresou rceWithEmbeddedCredentials); 551 UseCounter::count(frame()->document(), UseCounter::RequestedSubresou rceWithEmbeddedCredentials);
552 } 552 }
553 553
554 // Check for mixed content. We do this second-to-last so that when folks blo ck 554 // Check for mixed content. We do this second-to-last so that when folks blo ck
555 // mixed content with a CSP policy, they don't get a warning. They'll still 555 // mixed content with a CSP policy, they don't get a warning. They'll still
556 // get a warning in the console about CSP blocking the load. 556 // get a warning in the console about CSP blocking the load.
557 MixedContentChecker::ReportingStatus mixedContentReporting = forPreload ? 557 MixedContentChecker::ReportingStatus mixedContentReporting = forPreload ?
558 MixedContentChecker::SuppressReport : MixedContentChecker::SendReport; 558 MixedContentChecker::SuppressReport : MixedContentChecker::SendReport;
559 if (MixedContentChecker::shouldBlockFetch(frame(), resourceRequest, url, mix edContentReporting)) 559 // TODO(mkwst): Skip mixed content checks when UIR is enabled. For science. (Remove this.)
560 return ResourceRequestBlockedReasonMixedContent; 560 WebInsecureRequestPolicy relevantPolicy = m_document ? m_document->getInsecu reRequestPolicy() : frame()->loader().getInsecureRequestPolicy();
561 if (!(relevantPolicy & kUpgradeInsecureRequests)) {
562 if (MixedContentChecker::shouldBlockFetch(frame(), resourceRequest, url, mixedContentReporting))
563 return ResourceRequestBlockedReasonMixedContent;
564 }
561 565
562 // Let the client have the final say into whether or not the load should pro ceed. 566 // Let the client have the final say into whether or not the load should pro ceed.
563 DocumentLoader* documentLoader = masterDocumentLoader(); 567 DocumentLoader* documentLoader = masterDocumentLoader();
564 if (documentLoader && documentLoader->subresourceFilter() && type != Resourc e::MainResource && type != Resource::ImportResource && !documentLoader->subresou rceFilter()->allowLoad(url, resourceRequest.requestContext())) 568 if (documentLoader && documentLoader->subresourceFilter() && type != Resourc e::MainResource && type != Resource::ImportResource && !documentLoader->subresou rceFilter()->allowLoad(url, resourceRequest.requestContext()))
565 return ResourceRequestBlockedReasonSubresourceFilter; 569 return ResourceRequestBlockedReasonSubresourceFilter;
566 570
567 return ResourceRequestBlockedReasonNone; 571 return ResourceRequestBlockedReasonNone;
568 } 572 }
569 573
570 bool FrameFetchContext::contentSecurityPolicyBlocksRequest(Resource::Type type, const ResourceRequest& resourceRequest, const KURL& url, const ResourceLoaderOpt ions& options, bool forPreload, ResourceRequest::RedirectStatus redirectStatus) const 574 bool FrameFetchContext::contentSecurityPolicyBlocksRequest(Resource::Type type, const ResourceRequest& resourceRequest, const KURL& url, const ResourceLoaderOpt ions& options, bool forPreload, ResourceRequest::RedirectStatus redirectStatus) const
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 { 679 {
676 KURL url = fetchRequest.resourceRequest().url(); 680 KURL url = fetchRequest.resourceRequest().url();
677 681
678 // Tack an 'Upgrade-Insecure-Requests' header to outgoing navigational reque sts, as described in 682 // Tack an 'Upgrade-Insecure-Requests' header to outgoing navigational reque sts, as described in
679 // https://w3c.github.io/webappsec/specs/upgrade/#feature-detect 683 // https://w3c.github.io/webappsec/specs/upgrade/#feature-detect
680 if (fetchRequest.resourceRequest().frameType() != WebURLRequest::FrameTypeNo ne) 684 if (fetchRequest.resourceRequest().frameType() != WebURLRequest::FrameTypeNo ne)
681 fetchRequest.mutableResourceRequest().addHTTPHeaderField("Upgrade-Insecu re-Requests", "1"); 685 fetchRequest.mutableResourceRequest().addHTTPHeaderField("Upgrade-Insecu re-Requests", "1");
682 686
683 // If we don't yet have an |m_document| (because we're loading an iframe, fo r instance), check the FrameLoader's policy. 687 // If we don't yet have an |m_document| (because we're loading an iframe, fo r instance), check the FrameLoader's policy.
684 WebInsecureRequestPolicy relevantPolicy = m_document ? m_document->getInsecu reRequestPolicy() : frame()->loader().getInsecureRequestPolicy(); 688 WebInsecureRequestPolicy relevantPolicy = m_document ? m_document->getInsecu reRequestPolicy() : frame()->loader().getInsecureRequestPolicy();
685 SecurityContext::InsecureNavigationsSet* relevantNavigationSet = m_document ? m_document->insecureNavigationsToUpgrade() : frame()->loader().insecureNavigat ionsToUpgrade();
686 689
690 // printf("Setting %s policy to %d\n", url.getString().utf8().data(), releva ntPolicy);
691
692 fetchRequest.mutableResourceRequest().setInsecureRequestPolicy(relevantPolic y);
693
694 /*
687 if (url.protocolIs("http") && relevantPolicy & kUpgradeInsecureRequests) { 695 if (url.protocolIs("http") && relevantPolicy & kUpgradeInsecureRequests) {
688 // We always upgrade requests that meet any of the following criteria: 696 // We always upgrade requests that meet any of the following criteria:
689 // 697 //
690 // 1. Are for subresources (including nested frames). 698 // 1. Are for subresources (including nested frames).
691 // 2. Are form submissions. 699 // 2. Are form submissions.
692 // 3. Whose hosts are contained in the document's InsecureNavigationSet. 700 // 3. Whose hosts are contained in the document's InsecureNavigationSet.
701 SecurityContext::InsecureNavigationsSet* relevantNavigationSet = m_docum ent ? m_document->insecureNavigationsToUpgrade() : frame()->loader().insecureNav igationsToUpgrade();
693 const ResourceRequest& request = fetchRequest.resourceRequest(); 702 const ResourceRequest& request = fetchRequest.resourceRequest();
694 if (request.frameType() == WebURLRequest::FrameTypeNone 703 if (request.frameType() == WebURLRequest::FrameTypeNone
695 || request.frameType() == WebURLRequest::FrameTypeNested 704 || request.frameType() == WebURLRequest::FrameTypeNested
696 || request.requestContext() == WebURLRequest::RequestContextForm 705 || request.requestContext() == WebURLRequest::RequestContextForm
697 || (!url.host().isNull() && relevantNavigationSet->contains(url.host ().impl()->hash()))) 706 || (!url.host().isNull() && relevantNavigationSet->contains(url.host ().impl()->hash())))
698 { 707 {
699 UseCounter::count(m_document, UseCounter::UpgradeInsecureRequestsUpg radedRequest); 708 UseCounter::count(m_document, UseCounter::UpgradeInsecureRequestsUpg radedRequest);
700 url.setProtocol("https"); 709 url.setProtocol("https");
701 if (url.port() == 80) 710 if (url.port() == 80)
702 url.setPort(443); 711 url.setPort(443);
703 fetchRequest.mutableResourceRequest().setURL(url); 712 fetchRequest.mutableResourceRequest().setURL(url);
704 } 713 }
705 } 714 }
715 */
706 } 716 }
707 717
708 void FrameFetchContext::addClientHintsIfNecessary(FetchRequest& fetchRequest) 718 void FrameFetchContext::addClientHintsIfNecessary(FetchRequest& fetchRequest)
709 { 719 {
710 if (!RuntimeEnabledFeatures::clientHintsEnabled() || !m_document) 720 if (!RuntimeEnabledFeatures::clientHintsEnabled() || !m_document)
711 return; 721 return;
712 722
713 bool shouldSendDPR = m_document->clientHintsPreferences().shouldSendDPR() || fetchRequest.clientHintsPreferences().shouldSendDPR(); 723 bool shouldSendDPR = m_document->clientHintsPreferences().shouldSendDPR() || fetchRequest.clientHintsPreferences().shouldSendDPR();
714 bool shouldSendResourceWidth = m_document->clientHintsPreferences().shouldSe ndResourceWidth() || fetchRequest.clientHintsPreferences().shouldSendResourceWid th(); 724 bool shouldSendResourceWidth = m_document->clientHintsPreferences().shouldSe ndResourceWidth() || fetchRequest.clientHintsPreferences().shouldSendResourceWid th();
715 bool shouldSendViewportWidth = m_document->clientHintsPreferences().shouldSe ndViewportWidth() || fetchRequest.clientHintsPreferences().shouldSendViewportWid th(); 725 bool shouldSendViewportWidth = m_document->clientHintsPreferences().shouldSe ndViewportWidth() || fetchRequest.clientHintsPreferences().shouldSendViewportWid th();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 } 795 }
786 796
787 DEFINE_TRACE(FrameFetchContext) 797 DEFINE_TRACE(FrameFetchContext)
788 { 798 {
789 visitor->trace(m_document); 799 visitor->trace(m_document);
790 visitor->trace(m_documentLoader); 800 visitor->trace(m_documentLoader);
791 FetchContext::trace(visitor); 801 FetchContext::trace(visitor);
792 } 802 }
793 803
794 } // namespace blink 804 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698