OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights |
3 * reserved. | 3 * reserved. |
4 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 4 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
5 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 5 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
6 * (http://www.torchmobile.com/) | 6 * (http://www.torchmobile.com/) |
7 * Copyright (C) 2008 Alp Toker <alp@atoker.com> | 7 * Copyright (C) 2008 Alp Toker <alp@atoker.com> |
8 * Copyright (C) Research In Motion Limited 2009. All rights reserved. | 8 * Copyright (C) Research In Motion Limited 2009. All rights reserved. |
9 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com> | 9 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com> |
10 * Copyright (C) 2011 Google Inc. All rights reserved. | 10 * Copyright (C) 2011 Google Inc. All rights reserved. |
(...skipping 1593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1604 NavigationType navigationType = determineNavigationType( | 1604 NavigationType navigationType = determineNavigationType( |
1605 type, | 1605 type, |
1606 frameLoadRequest.resourceRequest().httpBody() || frameLoadRequest.form(), | 1606 frameLoadRequest.resourceRequest().httpBody() || frameLoadRequest.form(), |
1607 frameLoadRequest.triggeringEvent()); | 1607 frameLoadRequest.triggeringEvent()); |
1608 frameLoadRequest.resourceRequest().setRequestContext( | 1608 frameLoadRequest.resourceRequest().setRequestContext( |
1609 determineRequestContextFromNavigationType(navigationType)); | 1609 determineRequestContextFromNavigationType(navigationType)); |
1610 frameLoadRequest.resourceRequest().setFrameType( | 1610 frameLoadRequest.resourceRequest().setFrameType( |
1611 m_frame->isMainFrame() ? WebURLRequest::FrameTypeTopLevel | 1611 m_frame->isMainFrame() ? WebURLRequest::FrameTypeTopLevel |
1612 : WebURLRequest::FrameTypeNested); | 1612 : WebURLRequest::FrameTypeNested); |
1613 ResourceRequest& request = frameLoadRequest.resourceRequest(); | 1613 ResourceRequest& request = frameLoadRequest.resourceRequest(); |
1614 upgradeInsecureRequest(request, nullptr); | 1614 |
| 1615 // Record the latest requiredCSP value that will be used when sending this |
| 1616 // request. |
| 1617 recordLatestRequiredCSP(); |
| 1618 modifyRequestForCSP(request, nullptr); |
1615 if (!shouldContinueForNavigationPolicy( | 1619 if (!shouldContinueForNavigationPolicy( |
1616 request, frameLoadRequest.substituteData(), nullptr, | 1620 request, frameLoadRequest.substituteData(), nullptr, |
1617 frameLoadRequest.shouldCheckMainWorldContentSecurityPolicy(), | 1621 frameLoadRequest.shouldCheckMainWorldContentSecurityPolicy(), |
1618 navigationType, navigationPolicy, | 1622 navigationType, navigationPolicy, |
1619 type == FrameLoadTypeReplaceCurrentItem, | 1623 type == FrameLoadTypeReplaceCurrentItem, |
1620 frameLoadRequest.clientRedirect() == | 1624 frameLoadRequest.clientRedirect() == |
1621 ClientRedirectPolicy::ClientRedirect, | 1625 ClientRedirectPolicy::ClientRedirect, |
1622 frameLoadRequest.form())) | 1626 frameLoadRequest.form())) |
1623 return; | 1627 return; |
1624 | 1628 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1816 | 1820 |
1817 // FIXME: We need a way to propagate insecure requests policy flags to | 1821 // FIXME: We need a way to propagate insecure requests policy flags to |
1818 // out-of-process frames. For now, we'll always use default behavior. | 1822 // out-of-process frames. For now, we'll always use default behavior. |
1819 if (!parentFrame->isLocalFrame()) | 1823 if (!parentFrame->isLocalFrame()) |
1820 return nullptr; | 1824 return nullptr; |
1821 | 1825 |
1822 DCHECK(toLocalFrame(parentFrame)->document()); | 1826 DCHECK(toLocalFrame(parentFrame)->document()); |
1823 return toLocalFrame(parentFrame)->document()->insecureNavigationsToUpgrade(); | 1827 return toLocalFrame(parentFrame)->document()->insecureNavigationsToUpgrade(); |
1824 } | 1828 } |
1825 | 1829 |
1826 void FrameLoader::upgradeInsecureRequest(ResourceRequest& resourceRequest, | 1830 void FrameLoader::modifyRequestForCSP(ResourceRequest& resourceRequest, |
1827 Document* document) const { | 1831 Document* document) const { |
| 1832 if (RuntimeEnabledFeatures::embedderCSPEnforcementEnabled() && |
| 1833 !requiredCSP().isEmpty()) { |
| 1834 // TODO(amalika): Strengthen this DCHECK that requiredCSP has proper format |
| 1835 DCHECK(requiredCSP().getString().containsOnlyASCII()); |
| 1836 resourceRequest.setHTTPHeaderField(HTTPNames::Embedding_CSP, requiredCSP()); |
| 1837 } |
| 1838 |
1828 // Tack an 'Upgrade-Insecure-Requests' header to outgoing navigational | 1839 // Tack an 'Upgrade-Insecure-Requests' header to outgoing navigational |
1829 // requests, as described in | 1840 // requests, as described in |
1830 // https://w3c.github.io/webappsec/specs/upgrade/#feature-detect | 1841 // https://w3c.github.io/webappsec/specs/upgrade/#feature-detect |
1831 if (resourceRequest.frameType() != WebURLRequest::FrameTypeNone) { | 1842 if (resourceRequest.frameType() != WebURLRequest::FrameTypeNone) { |
1832 // Early return if the request has already been upgraded. | 1843 // Early return if the request has already been upgraded. |
1833 if (resourceRequest.httpHeaderField("Upgrade-Insecure-Requests") == | 1844 if (resourceRequest.httpHeaderField("Upgrade-Insecure-Requests") == |
1834 AtomicString("1")) | 1845 AtomicString("1")) |
1835 return; | 1846 return; |
1836 | 1847 |
1837 resourceRequest.addHTTPHeaderField("Upgrade-Insecure-Requests", "1"); | 1848 resourceRequest.addHTTPHeaderField("Upgrade-Insecure-Requests", "1"); |
1838 } | 1849 } |
1839 | 1850 |
| 1851 upgradeInsecureRequest(resourceRequest, document); |
| 1852 } |
| 1853 |
| 1854 void FrameLoader::upgradeInsecureRequest(ResourceRequest& resourceRequest, |
| 1855 Document* document) const { |
1840 KURL url = resourceRequest.url(); | 1856 KURL url = resourceRequest.url(); |
1841 | 1857 |
1842 // If we don't yet have an |m_document| (because we're loading an iframe, for | 1858 // If we don't yet have an |m_document| (because we're loading an iframe, for |
1843 // instance), check the FrameLoader's policy. | 1859 // instance), check the FrameLoader's policy. |
1844 WebInsecureRequestPolicy relevantPolicy = | 1860 WebInsecureRequestPolicy relevantPolicy = |
1845 document ? document->getInsecureRequestPolicy() | 1861 document ? document->getInsecureRequestPolicy() |
1846 : getInsecureRequestPolicy(); | 1862 : getInsecureRequestPolicy(); |
1847 SecurityContext::InsecureNavigationsSet* relevantNavigationSet = | 1863 SecurityContext::InsecureNavigationsSet* relevantNavigationSet = |
1848 document ? document->insecureNavigationsToUpgrade() | 1864 document ? document->insecureNavigationsToUpgrade() |
1849 : insecureNavigationsToUpgrade(); | 1865 : insecureNavigationsToUpgrade(); |
(...skipping 12 matching lines...) Expand all Loading... |
1862 UseCounter::count(document, | 1878 UseCounter::count(document, |
1863 UseCounter::UpgradeInsecureRequestsUpgradedRequest); | 1879 UseCounter::UpgradeInsecureRequestsUpgradedRequest); |
1864 url.setProtocol("https"); | 1880 url.setProtocol("https"); |
1865 if (url.port() == 80) | 1881 if (url.port() == 80) |
1866 url.setPort(443); | 1882 url.setPort(443); |
1867 resourceRequest.setURL(url); | 1883 resourceRequest.setURL(url); |
1868 } | 1884 } |
1869 } | 1885 } |
1870 } | 1886 } |
1871 | 1887 |
| 1888 void FrameLoader::recordLatestRequiredCSP() { |
| 1889 m_requiredCSP = m_frame->owner() ? m_frame->owner()->csp() : nullAtom; |
| 1890 } |
| 1891 |
1872 std::unique_ptr<TracedValue> FrameLoader::toTracedValue() const { | 1892 std::unique_ptr<TracedValue> FrameLoader::toTracedValue() const { |
1873 std::unique_ptr<TracedValue> tracedValue = TracedValue::create(); | 1893 std::unique_ptr<TracedValue> tracedValue = TracedValue::create(); |
1874 tracedValue->beginDictionary("frame"); | 1894 tracedValue->beginDictionary("frame"); |
1875 tracedValue->setString( | 1895 tracedValue->setString( |
1876 "id_ref", | 1896 "id_ref", |
1877 String::format( | 1897 String::format( |
1878 "0x%" PRIx64, | 1898 "0x%" PRIx64, |
1879 static_cast<uint64_t>(reinterpret_cast<uintptr_t>(m_frame.get())))); | 1899 static_cast<uint64_t>(reinterpret_cast<uintptr_t>(m_frame.get())))); |
1880 tracedValue->endDictionary(); | 1900 tracedValue->endDictionary(); |
1881 tracedValue->setBoolean("isLoadingMainFrame", isLoadingMainFrame()); | 1901 tracedValue->setBoolean("isLoadingMainFrame", isLoadingMainFrame()); |
1882 tracedValue->setString("stateMachine", m_stateMachine.toString()); | 1902 tracedValue->setString("stateMachine", m_stateMachine.toString()); |
1883 tracedValue->setString("provisionalDocumentLoaderURL", | 1903 tracedValue->setString("provisionalDocumentLoaderURL", |
1884 m_provisionalDocumentLoader | 1904 m_provisionalDocumentLoader |
1885 ? m_provisionalDocumentLoader->url() | 1905 ? m_provisionalDocumentLoader->url() |
1886 : String()); | 1906 : String()); |
1887 tracedValue->setString("documentLoaderURL", | 1907 tracedValue->setString("documentLoaderURL", |
1888 m_documentLoader ? m_documentLoader->url() : String()); | 1908 m_documentLoader ? m_documentLoader->url() : String()); |
1889 return tracedValue; | 1909 return tracedValue; |
1890 } | 1910 } |
1891 | 1911 |
1892 inline void FrameLoader::takeObjectSnapshot() const { | 1912 inline void FrameLoader::takeObjectSnapshot() const { |
1893 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID("loading", "FrameLoader", this, | 1913 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID("loading", "FrameLoader", this, |
1894 toTracedValue()); | 1914 toTracedValue()); |
1895 } | 1915 } |
1896 | 1916 |
1897 } // namespace blink | 1917 } // namespace blink |
OLD | NEW |