Make it possible to call ContentSecurityPolicy::upgradeInsecureRequestIfNeeded()...
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Mar 2018 00:12:32 +0000 (00:12 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Mar 2018 00:12:32 +0000 (00:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184029

Reviewed by Youenn Fablet.

Make it possible to call ContentSecurityPolicy::upgradeInsecureRequestIfNeeded() from non-main threads
by having it use SecurityOriginData (which is safe to construct on non-main threads) instead of
SecurityOrigin (which isn't).

ContentSecurityPolicy::upgradeInsecureRequestIfNeeded() is already called from non-main thread in
FetchLoader, XHR and WebSocket when used in workers. This wasn't safe.

* loader/DocumentWriter.cpp:
(WebCore::DocumentWriter::begin):
* page/csp/ContentSecurityPolicy.cpp:
(WebCore::ContentSecurityPolicy::upgradeInsecureRequestIfNeeded const):
(WebCore::ContentSecurityPolicy::setUpgradeInsecureRequests):
(WebCore::ContentSecurityPolicy::takeNavigationRequestsToUpgrade):
(WebCore::ContentSecurityPolicy::setInsecureNavigationRequestsToUpgrade):
* page/csp/ContentSecurityPolicy.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230017 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/loader/DocumentWriter.cpp
Source/WebCore/page/csp/ContentSecurityPolicy.cpp
Source/WebCore/page/csp/ContentSecurityPolicy.h

index 24fab53..03153ec 100644 (file)
@@ -1,3 +1,26 @@
+2018-03-27  Chris Dumez  <cdumez@apple.com>
+
+        Make it possible to call ContentSecurityPolicy::upgradeInsecureRequestIfNeeded() from non-main threads
+        https://bugs.webkit.org/show_bug.cgi?id=184029
+
+        Reviewed by Youenn Fablet.
+
+        Make it possible to call ContentSecurityPolicy::upgradeInsecureRequestIfNeeded() from non-main threads
+        by having it use SecurityOriginData (which is safe to construct on non-main threads) instead of
+        SecurityOrigin (which isn't).
+
+        ContentSecurityPolicy::upgradeInsecureRequestIfNeeded() is already called from non-main thread in
+        FetchLoader, XHR and WebSocket when used in workers. This wasn't safe.
+
+        * loader/DocumentWriter.cpp:
+        (WebCore::DocumentWriter::begin):
+        * page/csp/ContentSecurityPolicy.cpp:
+        (WebCore::ContentSecurityPolicy::upgradeInsecureRequestIfNeeded const):
+        (WebCore::ContentSecurityPolicy::setUpgradeInsecureRequests):
+        (WebCore::ContentSecurityPolicy::takeNavigationRequestsToUpgrade):
+        (WebCore::ContentSecurityPolicy::setInsecureNavigationRequestsToUpgrade):
+        * page/csp/ContentSecurityPolicy.h:
+
 2018-03-27  Daniel Bates  <dabates@apple.com>
 
         Attempt to fix media control layout tests after <https://trac.webkit.org/changeset/230006/>
index 0e9faf4..a54afb0 100644 (file)
@@ -155,7 +155,7 @@ bool DocumentWriter::begin(const URL& urlReference, bool dispatch, Document* own
     // requests in new navigation contexts. Although this information is present when we construct the
     // Document object, it is discard in the subsequent 'clear' statements below. So, we must capture it
     // so we can restore it.
-    HashSet<RefPtr<SecurityOrigin>> insecureNavigationRequestsToUpgrade;
+    HashSet<SecurityOriginData> insecureNavigationRequestsToUpgrade;
     if (auto* existingDocument = m_frame->document())
         insecureNavigationRequestsToUpgrade = existingDocument->contentSecurityPolicy()->takeNavigationRequestsToUpgrade();
     
index ae62a1f..0c2036f 100644 (file)
@@ -823,7 +823,7 @@ void ContentSecurityPolicy::upgradeInsecureRequestIfNeeded(URL& url, InsecureReq
     if (!url.protocolIs("http") && !url.protocolIs("ws"))
         return;
 
-    bool upgradeRequest = m_insecureNavigationRequestsToUpgrade.contains(SecurityOrigin::create(url));
+    bool upgradeRequest = m_insecureNavigationRequestsToUpgrade.contains(SecurityOriginData::fromURL(url));
     if (requestType == InsecureRequestType::Load || requestType == InsecureRequestType::FormSubmission)
         upgradeRequest |= m_upgradeInsecureRequests;
     
@@ -858,7 +858,7 @@ void ContentSecurityPolicy::setUpgradeInsecureRequests(bool upgradeInsecureReque
     else if (upgradeURL.protocolIs("wss"))
         upgradeURL.setProtocol("ws");
     
-    m_insecureNavigationRequestsToUpgrade.add(SecurityOrigin::create(upgradeURL));
+    m_insecureNavigationRequestsToUpgrade.add(SecurityOriginData::fromURL(upgradeURL));
 }
 
 void ContentSecurityPolicy::inheritInsecureNavigationRequestsToUpgradeFromOpener(const ContentSecurityPolicy& other)
@@ -866,12 +866,12 @@ void ContentSecurityPolicy::inheritInsecureNavigationRequestsToUpgradeFromOpener
     m_insecureNavigationRequestsToUpgrade.add(other.m_insecureNavigationRequestsToUpgrade.begin(), other.m_insecureNavigationRequestsToUpgrade.end());
 }
 
-HashSet<RefPtr<SecurityOrigin>>&& ContentSecurityPolicy::takeNavigationRequestsToUpgrade()
+HashSet<SecurityOriginData> ContentSecurityPolicy::takeNavigationRequestsToUpgrade()
 {
     return WTFMove(m_insecureNavigationRequestsToUpgrade);
 }
 
-void ContentSecurityPolicy::setInsecureNavigationRequestsToUpgrade(HashSet<RefPtr<SecurityOrigin>>&& insecureNavigationRequests)
+void ContentSecurityPolicy::setInsecureNavigationRequestsToUpgrade(HashSet<SecurityOriginData>&& insecureNavigationRequests)
 {
     m_insecureNavigationRequestsToUpgrade = WTFMove(insecureNavigationRequests);
 }
index fbd8d39..669a8ff 100644 (file)
@@ -164,9 +164,9 @@ public:
     void upgradeInsecureRequestIfNeeded(ResourceRequest&, InsecureRequestType) const;
     void upgradeInsecureRequestIfNeeded(URL&, InsecureRequestType) const;
 
-    HashSet<RefPtr<SecurityOrigin>>&& takeNavigationRequestsToUpgrade();
+    HashSet<SecurityOriginData> takeNavigationRequestsToUpgrade();
     void inheritInsecureNavigationRequestsToUpgradeFromOpener(const ContentSecurityPolicy&);
-    void setInsecureNavigationRequestsToUpgrade(HashSet<RefPtr<SecurityOrigin>>&&);
+    void setInsecureNavigationRequestsToUpgrade(HashSet<SecurityOriginData>&&);
 
 private:
     void logToConsole(const String& message, const String& contextURL = String(), const WTF::OrdinalNumber& contextLine = WTF::OrdinalNumber::beforeFirst(), JSC::ExecState* = nullptr) const;
@@ -218,7 +218,7 @@ private:
     bool m_hasAPIPolicy { false };
     OptionSet<ContentSecurityPolicyHashAlgorithm> m_hashAlgorithmsForInlineScripts;
     OptionSet<ContentSecurityPolicyHashAlgorithm> m_hashAlgorithmsForInlineStylesheets;
-    HashSet<RefPtr<SecurityOrigin>> m_insecureNavigationRequestsToUpgrade;
+    HashSet<SecurityOriginData> m_insecureNavigationRequestsToUpgrade;
     mutable std::optional<ContentSecurityPolicyResponseHeaders> m_cachedResponseHeaders;
 };