Title: [263964] trunk
Revision
263964
Author
[email protected]
Date
2020-07-06 01:49:29 -0700 (Mon, 06 Jul 2020)

Log Message

[GTK][WPE] Change the cookies accept policy when ITP is enabled
https://bugs.webkit.org/show_bug.cgi?id=213502

Reviewed by Michael Catanzaro.

Source/WebCore:

Set the accept policy to always when ITP is enabled and no-third-party is set, otherwise cookies access granted
by request storage access would still be rejected by libsoup if policy is set to no-third-party.

* platform/network/NetworkStorageSession.cpp:
(WebCore::NetworkStorageSession::setResourceLoadStatisticsEnabled): Move here the implementation for ports not
using soup.
* platform/network/NetworkStorageSession.h:
* platform/network/soup/NetworkStorageSessionSoup.cpp:
(WebCore::NetworkStorageSession::NetworkStorageSession): Initialize cookie accept policy.
(WebCore::NetworkStorageSession::setCookieStorage): Set here the accept policy of the new jar.
(WebCore::NetworkStorageSession::setCookieAcceptPolicy): Set the cookie accept policy taking into account that
if ITP is enabled and no-third-party is set we save the policy but use always instead.
(WebCore::NetworkStorageSession::cookieAcceptPolicy const): Remove the default case of the switch.
(WebCore::NetworkStorageSession::setResourceLoadStatisticsEnabled): When enabled, save current policy and set
always if no-third-party is set. When disabled, restore the saved policy.

Source/WebKit:

* NetworkProcess/Cookies/soup/WebCookieManagerSoup.cpp:
(WebKit::WebCookieManager::platformSetHTTPCookieAcceptPolicy): Use NetworkStorageSession::setCookieAcceptPolicy().
* NetworkProcess/soup/NetworkSessionSoup.cpp:
(WebKit::NetworkSessionSoup::setCookiePersistentStorage): Do not change the accept policy, it's now done by
NetworkStorageSession when the new cookie jar is set.
* UIProcess/API/glib/WebKitCookieManager.cpp: Update API docs.
* UIProcess/API/glib/WebKitWebsiteDataManager.cpp: Ditto.

Tools:

Add tests to check the policy is changed and restored correctly when ITP is enabled and disabled.

* TestWebKitAPI/Tests/WebKitGLib/TestCookieManager.cpp:
(testCookieManagerAcceptPolicy):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (263963 => 263964)


--- trunk/Source/WebCore/ChangeLog	2020-07-06 08:35:31 UTC (rev 263963)
+++ trunk/Source/WebCore/ChangeLog	2020-07-06 08:49:29 UTC (rev 263964)
@@ -1,3 +1,26 @@
+2020-07-06  Carlos Garcia Campos  <[email protected]>
+
+        [GTK][WPE] Change the cookies accept policy when ITP is enabled
+        https://bugs.webkit.org/show_bug.cgi?id=213502
+
+        Reviewed by Michael Catanzaro.
+
+        Set the accept policy to always when ITP is enabled and no-third-party is set, otherwise cookies access granted
+        by request storage access would still be rejected by libsoup if policy is set to no-third-party.
+
+        * platform/network/NetworkStorageSession.cpp:
+        (WebCore::NetworkStorageSession::setResourceLoadStatisticsEnabled): Move here the implementation for ports not
+        using soup.
+        * platform/network/NetworkStorageSession.h:
+        * platform/network/soup/NetworkStorageSessionSoup.cpp:
+        (WebCore::NetworkStorageSession::NetworkStorageSession): Initialize cookie accept policy.
+        (WebCore::NetworkStorageSession::setCookieStorage): Set here the accept policy of the new jar.
+        (WebCore::NetworkStorageSession::setCookieAcceptPolicy): Set the cookie accept policy taking into account that
+        if ITP is enabled and no-third-party is set we save the policy but use always instead.
+        (WebCore::NetworkStorageSession::cookieAcceptPolicy const): Remove the default case of the switch.
+        (WebCore::NetworkStorageSession::setResourceLoadStatisticsEnabled): When enabled, save current policy and set
+        always if no-third-party is set. When disabled, restore the saved policy.
+
 2020-07-06  Alicia Boya GarcĂ­a  <[email protected]>
 
         [MSE][GStreamer] Don't skip samples past media duration in AppendPipeline

Modified: trunk/Source/WebCore/platform/network/NetworkStorageSession.cpp (263963 => 263964)


--- trunk/Source/WebCore/platform/network/NetworkStorageSession.cpp	2020-07-06 08:35:31 UTC (rev 263963)
+++ trunk/Source/WebCore/platform/network/NetworkStorageSession.cpp	2020-07-06 08:49:29 UTC (rev 263964)
@@ -67,6 +67,13 @@
 
 #if ENABLE(RESOURCE_LOAD_STATISTICS)
 
+#if !USE(SOUP)
+void NetworkStorageSession::setResourceLoadStatisticsEnabled(bool enabled)
+{
+    m_isResourceLoadStatisticsEnabled = enabled;
+}
+#endif
+
 bool NetworkStorageSession::shouldBlockThirdPartyCookies(const RegistrableDomain& registrableDomain) const
 {
     if (!m_isResourceLoadStatisticsEnabled || registrableDomain.isEmpty())

Modified: trunk/Source/WebCore/platform/network/NetworkStorageSession.h (263963 => 263964)


--- trunk/Source/WebCore/platform/network/NetworkStorageSession.h	2020-07-06 08:35:31 UTC (rev 263963)
+++ trunk/Source/WebCore/platform/network/NetworkStorageSession.h	2020-07-06 08:49:29 UTC (rev 263964)
@@ -129,6 +129,7 @@
 
     SoupCookieJar* cookieStorage() const { return m_cookieStorage.get(); }
     void setCookieStorage(GRefPtr<SoupCookieJar>&&);
+    void setCookieAcceptPolicy(HTTPCookieAcceptPolicy);
     void setCookieObserverHandler(Function<void ()>&&);
     void getCredentialFromPersistentStorage(const ProtectionSpace&, GCancellable*, Function<void (Credential&&)>&& completionHandler);
     void saveCredentialToPersistentStorage(const ProtectionSpace&, const Credential&);
@@ -177,7 +178,7 @@
 #endif
 
 #if ENABLE(RESOURCE_LOAD_STATISTICS)
-    void setResourceLoadStatisticsEnabled(bool enabled) { m_isResourceLoadStatisticsEnabled = enabled; }
+    WEBCORE_EXPORT void setResourceLoadStatisticsEnabled(bool);
     WEBCORE_EXPORT bool shouldBlockCookies(const ResourceRequest&, Optional<FrameIdentifier>, Optional<PageIdentifier>, ShouldRelaxThirdPartyCookieBlocking) const;
     WEBCORE_EXPORT bool shouldBlockCookies(const URL& firstPartyForCookies, const URL& resource, Optional<FrameIdentifier>, Optional<PageIdentifier>, ShouldRelaxThirdPartyCookieBlocking) const;
     WEBCORE_EXPORT bool shouldBlockThirdPartyCookies(const RegistrableDomain&) const;
@@ -229,6 +230,7 @@
 #elif USE(SOUP)
     static void cookiesDidChange(NetworkStorageSession*);
 
+    HTTPCookieAcceptPolicy m_cookieAcceptPolicy;
     GRefPtr<SoupCookieJar> m_cookieStorage;
     Function<void ()> m_cookieObserverHandler;
 #elif USE(CURL)

Modified: trunk/Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp (263963 => 263964)


--- trunk/Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp	2020-07-06 08:35:31 UTC (rev 263963)
+++ trunk/Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp	2020-07-06 08:49:29 UTC (rev 263964)
@@ -56,9 +56,10 @@
 
 NetworkStorageSession::NetworkStorageSession(PAL::SessionID sessionID)
     : m_sessionID(sessionID)
+    , m_cookieAcceptPolicy(HTTPCookieAcceptPolicy::OnlyFromMainDocumentDomain)
     , m_cookieStorage(adoptGRef(soup_cookie_jar_new()))
 {
-    soup_cookie_jar_set_accept_policy(m_cookieStorage.get(), SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY);
+    setCookieAcceptPolicy(m_cookieAcceptPolicy);
     g_signal_connect_swapped(m_cookieStorage.get(), "changed", G_CALLBACK(cookiesDidChange), this);
 }
 
@@ -76,6 +77,7 @@
 void NetworkStorageSession::setCookieStorage(GRefPtr<SoupCookieJar>&& jar)
 {
     g_signal_handlers_disconnect_matched(m_cookieStorage.get(), G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, this);
+    soup_cookie_jar_set_accept_policy(jar.get(), soup_cookie_jar_get_accept_policy(m_cookieStorage.get()));
     m_cookieStorage = WTFMove(jar);
     g_signal_connect_swapped(m_cookieStorage.get(), "changed", G_CALLBACK(cookiesDidChange), this);
 }
@@ -242,6 +244,33 @@
 #endif
 }
 
+void NetworkStorageSession::setCookieAcceptPolicy(HTTPCookieAcceptPolicy policy)
+{
+    if (m_isResourceLoadStatisticsEnabled && m_thirdPartyCookieBlockingMode == ThirdPartyCookieBlockingMode::All) {
+        m_cookieAcceptPolicy = policy;
+        if (m_cookieAcceptPolicy == HTTPCookieAcceptPolicy::OnlyFromMainDocumentDomain)
+            policy = HTTPCookieAcceptPolicy::AlwaysAccept;
+    }
+
+    SoupCookieJarAcceptPolicy soupPolicy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;
+    switch (policy) {
+    case HTTPCookieAcceptPolicy::AlwaysAccept:
+        soupPolicy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
+        break;
+    case HTTPCookieAcceptPolicy::Never:
+        soupPolicy = SOUP_COOKIE_JAR_ACCEPT_NEVER;
+        break;
+    case HTTPCookieAcceptPolicy::OnlyFromMainDocumentDomain:
+        soupPolicy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;
+        break;
+    case HTTPCookieAcceptPolicy::ExclusivelyFromMainDocumentDomain:
+        ASSERT_NOT_REACHED();
+        break;
+    }
+
+    soup_cookie_jar_set_accept_policy(cookieStorage(), soupPolicy);
+}
+
 HTTPCookieAcceptPolicy NetworkStorageSession::cookieAcceptPolicy() const
 {
     switch (soup_cookie_jar_get_accept_policy(cookieStorage())) {
@@ -249,11 +278,27 @@
         return HTTPCookieAcceptPolicy::AlwaysAccept;
     case SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY:
         return HTTPCookieAcceptPolicy::OnlyFromMainDocumentDomain;
-    default:
+    case SOUP_COOKIE_JAR_ACCEPT_NEVER:
         return HTTPCookieAcceptPolicy::Never;
     }
+    RELEASE_ASSERT_NOT_REACHED();
 }
 
+#if ENABLE(RESOURCE_LOAD_STATISTICS)
+void NetworkStorageSession::setResourceLoadStatisticsEnabled(bool enabled)
+{
+    if (enabled) {
+        m_cookieAcceptPolicy = cookieAcceptPolicy();
+        if (m_thirdPartyCookieBlockingMode == ThirdPartyCookieBlockingMode::All && m_cookieAcceptPolicy == HTTPCookieAcceptPolicy::OnlyFromMainDocumentDomain)
+            setCookieAcceptPolicy(HTTPCookieAcceptPolicy::AlwaysAccept);
+        m_isResourceLoadStatisticsEnabled = true;
+    } else {
+        m_isResourceLoadStatisticsEnabled = false;
+        setCookieAcceptPolicy(m_cookieAcceptPolicy);
+    }
+}
+#endif
+
 static inline bool httpOnlyCookieExists(const GSList* cookies, const gchar* name, const gchar* path)
 {
     for (const GSList* iter = cookies; iter; iter = g_slist_next(iter)) {

Modified: trunk/Source/WebKit/ChangeLog (263963 => 263964)


--- trunk/Source/WebKit/ChangeLog	2020-07-06 08:35:31 UTC (rev 263963)
+++ trunk/Source/WebKit/ChangeLog	2020-07-06 08:49:29 UTC (rev 263964)
@@ -1,3 +1,18 @@
+2020-07-06  Carlos Garcia Campos  <[email protected]>
+
+        [GTK][WPE] Change the cookies accept policy when ITP is enabled
+        https://bugs.webkit.org/show_bug.cgi?id=213502
+
+        Reviewed by Michael Catanzaro.
+
+        * NetworkProcess/Cookies/soup/WebCookieManagerSoup.cpp:
+        (WebKit::WebCookieManager::platformSetHTTPCookieAcceptPolicy): Use NetworkStorageSession::setCookieAcceptPolicy().
+        * NetworkProcess/soup/NetworkSessionSoup.cpp:
+        (WebKit::NetworkSessionSoup::setCookiePersistentStorage): Do not change the accept policy, it's now done by
+        NetworkStorageSession when the new cookie jar is set.
+        * UIProcess/API/glib/WebKitCookieManager.cpp: Update API docs.
+        * UIProcess/API/glib/WebKitWebsiteDataManager.cpp: Ditto.
+
 2020-07-05  Commit Queue  <[email protected]>
 
         Unreviewed, reverting r263960.

Modified: trunk/Source/WebKit/NetworkProcess/Cookies/soup/WebCookieManagerSoup.cpp (263963 => 263964)


--- trunk/Source/WebKit/NetworkProcess/Cookies/soup/WebCookieManagerSoup.cpp	2020-07-06 08:35:31 UTC (rev 263963)
+++ trunk/Source/WebKit/NetworkProcess/Cookies/soup/WebCookieManagerSoup.cpp	2020-07-06 08:49:29 UTC (rev 263964)
@@ -39,24 +39,8 @@
 
 void WebCookieManager::platformSetHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy policy)
 {
-    SoupCookieJarAcceptPolicy soupPolicy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;
-    switch (policy) {
-    case HTTPCookieAcceptPolicy::AlwaysAccept:
-        soupPolicy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS;
-        break;
-    case HTTPCookieAcceptPolicy::Never:
-        soupPolicy = SOUP_COOKIE_JAR_ACCEPT_NEVER;
-        break;
-    case HTTPCookieAcceptPolicy::OnlyFromMainDocumentDomain:
-        soupPolicy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;
-        break;
-    case HTTPCookieAcceptPolicy::ExclusivelyFromMainDocumentDomain:
-        ASSERT_NOT_REACHED();
-        break;
-    }
-
-    m_process.forEachNetworkStorageSession([soupPolicy] (const auto& session) {
-        soup_cookie_jar_set_accept_policy(session.cookieStorage(), soupPolicy);
+    m_process.forEachNetworkStorageSession([policy] (auto& session) {
+        session.setCookieAcceptPolicy(policy);
     });
 }
 

Modified: trunk/Source/WebKit/NetworkProcess/soup/NetworkSessionSoup.cpp (263963 => 263964)


--- trunk/Source/WebKit/NetworkProcess/soup/NetworkSessionSoup.cpp	2020-07-06 08:35:31 UTC (rev 263963)
+++ trunk/Source/WebKit/NetworkProcess/soup/NetworkSessionSoup.cpp	2020-07-06 08:49:29 UTC (rev 263964)
@@ -82,11 +82,7 @@
     case SoupCookiePersistentStorageType::SQLite:
         jar = adoptGRef(soup_cookie_jar_db_new(storagePath.utf8().data(), FALSE));
         break;
-    default:
-        ASSERT_NOT_REACHED();
     }
-
-    soup_cookie_jar_set_accept_policy(jar.get(), soup_cookie_jar_get_accept_policy(storageSession->cookieStorage()));
     storageSession->setCookieStorage(WTFMove(jar));
 
     m_networkSession->setCookieJar(storageSession->cookieStorage());

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitCookieManager.cpp (263963 => 263964)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitCookieManager.cpp	2020-07-06 08:35:31 UTC (rev 263963)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitCookieManager.cpp	2020-07-06 08:49:29 UTC (rev 263964)
@@ -185,6 +185,10 @@
  * @policy: a #WebKitCookieAcceptPolicy
  *
  * Set the cookie acceptance policy of @cookie_manager as @policy.
+ * Note that ITP has its own way to handle third-party cookies, so when it's enabled,
+ * and @policy is set to %WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY, %WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS
+ * will be used instead. Once disabled, the policy will be set back to %WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY.
+ * See also webkit_website_data_manager_set_itp_enabled().
  */
 void webkit_cookie_manager_set_accept_policy(WebKitCookieManager* manager, WebKitCookieAcceptPolicy policy)
 {
@@ -202,6 +206,9 @@
  * @user_data: (closure): the data to pass to callback function
  *
  * Asynchronously get the cookie acceptance policy of @cookie_manager.
+ * Note that when policy was set to %WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY and
+ * ITP is enabled, this will return %WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS.
+ * See also webkit_website_data_manager_set_itp_enabled().
  *
  * When the operation is finished, @callback will be called. You can then call
  * webkit_cookie_manager_get_accept_policy_finish() to get the result of the operation.

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitWebsiteDataManager.cpp (263963 => 263964)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitWebsiteDataManager.cpp	2020-07-06 08:35:31 UTC (rev 263963)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitWebsiteDataManager.cpp	2020-07-06 08:49:29 UTC (rev 263964)
@@ -841,8 +841,8 @@
  *
  * Enable or disable Intelligent Tracking Prevention (ITP). When ITP is enabled resource load statistics
  * are collected and used to decide whether to allow or block third-party cookies and prevent user tracking.
- * Note that when ITP is enabled the resources for which cookies are allowed will follow the accept policy
- * set with webkit_cookie_manager_set_accept_policy().
+ * Note that while ITP is enabled the accept policy %WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY is ignored and
+ * %WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS is used instead. See also webkit_cookie_manager_set_accept_policy().
  *
  * Since: 2.30
  */

Modified: trunk/Tools/ChangeLog (263963 => 263964)


--- trunk/Tools/ChangeLog	2020-07-06 08:35:31 UTC (rev 263963)
+++ trunk/Tools/ChangeLog	2020-07-06 08:49:29 UTC (rev 263964)
@@ -1,3 +1,15 @@
+2020-07-06  Carlos Garcia Campos  <[email protected]>
+
+        [GTK][WPE] Change the cookies accept policy when ITP is enabled
+        https://bugs.webkit.org/show_bug.cgi?id=213502
+
+        Reviewed by Michael Catanzaro.
+
+        Add tests to check the policy is changed and restored correctly when ITP is enabled and disabled.
+
+        * TestWebKitAPI/Tests/WebKitGLib/TestCookieManager.cpp:
+        (testCookieManagerAcceptPolicy):
+
 2020-07-06  Philippe Normand  <[email protected]>
 
         [Flatpak SDK] Misc updates

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestCookieManager.cpp (263963 => 263964)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestCookieManager.cpp	2020-07-06 08:35:31 UTC (rev 263963)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestCookieManager.cpp	2020-07-06 08:49:29 UTC (rev 263964)
@@ -275,6 +275,26 @@
     domains = test->getDomains();
     g_assert_nonnull(domains);
     g_assert_cmpint(g_strv_length(domains), ==, 0);
+
+    // ITP never uses NO_THIRD_PARTY.
+    auto* manager = webkit_web_context_get_website_data_manager(test->m_webContext.get());
+    webkit_website_data_manager_set_itp_enabled(manager, TRUE);
+    g_assert_cmpint(test->getAcceptPolicy(), ==, WEBKIT_COOKIE_POLICY_ACCEPT_NEVER);
+    test->setAcceptPolicy(WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY);
+    g_assert_cmpint(test->getAcceptPolicy(), ==, WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS);
+    webkit_website_data_manager_set_itp_enabled(manager, FALSE);
+    g_assert_cmpint(test->getAcceptPolicy(), ==, WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY);
+    webkit_website_data_manager_set_itp_enabled(manager, TRUE);
+    g_assert_cmpint(test->getAcceptPolicy(), ==, WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS);
+    webkit_website_data_manager_set_itp_enabled(manager, FALSE);
+    g_assert_cmpint(test->getAcceptPolicy(), ==, WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY);
+    test->setAcceptPolicy(WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS);
+    webkit_website_data_manager_set_itp_enabled(manager, TRUE);
+    g_assert_cmpint(test->getAcceptPolicy(), ==, WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS);
+    test->setAcceptPolicy(WEBKIT_COOKIE_POLICY_ACCEPT_NEVER);
+    g_assert_cmpint(test->getAcceptPolicy(), ==, WEBKIT_COOKIE_POLICY_ACCEPT_NEVER);
+    webkit_website_data_manager_set_itp_enabled(manager, FALSE);
+    g_assert_cmpint(test->getAcceptPolicy(), ==, WEBKIT_COOKIE_POLICY_ACCEPT_NEVER);
 }
 
 static void testCookieManagerAddCookie(CookieManagerTest* test, gconstpointer)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to