Title: [230002] trunk/Source
Revision
230002
Author
bfulg...@apple.com
Date
2018-03-27 13:27:55 -0700 (Tue, 27 Mar 2018)

Log Message

Further refine cookie read/write logging
https://bugs.webkit.org/show_bug.cgi?id=184044
<rdar://problem/38915610>

Reviewed by Chris Dumez.

Source/WebCore:

Export 'shouldBlockCookies' so that it can be accessed by the WebKit framework.

* platform/network/NetworkStorageSession.h:

Source/WebKit:

Cookie logging was passing the partition, rather than the first party, when logging, which
prevented logging in cases where partitioning or blocking was active. This patch corrects
these calls so that logging is generated in these cases, too.

* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::cookiesForDOM): Call log routines if needed.
(WebKit::NetworkConnectionToWebProcess::setCookiesFromDOM): Ditto.
* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::escapeIDForJSON): Make available to use in multiple functions.
(WebKit::NetworkResourceLoader::logCookieInformation const): Revise to use shared
convenience functions.
(WebKit::logBlockedCookieInformation): Added.
(WebKit::logCookieInformationInternal): Added.
(WebKit::NetworkResourceLoader::logCookieInformation): Revise to use shared
convenience functions.
* NetworkProcess/NetworkResourceLoader.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (230001 => 230002)


--- trunk/Source/WebCore/ChangeLog	2018-03-27 19:30:59 UTC (rev 230001)
+++ trunk/Source/WebCore/ChangeLog	2018-03-27 20:27:55 UTC (rev 230002)
@@ -1,3 +1,15 @@
+2018-03-27  Brent Fulgham  <bfulg...@apple.com>
+
+        Further refine cookie read/write logging
+        https://bugs.webkit.org/show_bug.cgi?id=184044
+        <rdar://problem/38915610>
+
+        Reviewed by Chris Dumez.
+
+        Export 'shouldBlockCookies' so that it can be accessed by the WebKit framework.
+
+        * platform/network/NetworkStorageSession.h:
+
 2018-03-27  Antoine Quint  <grao...@apple.com>
 
         [Web Animations] Stop using internals.pauseAnimationAtTimeOnElement() in favor of Web Animations API for animations tests

Modified: trunk/Source/WebCore/platform/network/NetworkStorageSession.h (230001 => 230002)


--- trunk/Source/WebCore/platform/network/NetworkStorageSession.h	2018-03-27 19:30:59 UTC (rev 230001)
+++ trunk/Source/WebCore/platform/network/NetworkStorageSession.h	2018-03-27 20:27:55 UTC (rev 230002)
@@ -103,7 +103,7 @@
 #if HAVE(CFNETWORK_STORAGE_PARTITIONING)
     WEBCORE_EXPORT String cookieStoragePartition(const ResourceRequest&, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID) const;
     WEBCORE_EXPORT bool shouldBlockCookies(const ResourceRequest&) const;
-    bool shouldBlockCookies(const URL& firstPartyForCookies, const URL& resource) const;
+    WEBCORE_EXPORT bool shouldBlockCookies(const URL& firstPartyForCookies, const URL& resource) const;
     WEBCORE_EXPORT String cookieStoragePartition(const URL& firstPartyForCookies, const URL& resource, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID) const;
     WEBCORE_EXPORT void setPrevalentDomainsToPartitionOrBlockCookies(const Vector<String>& domainsToPartition, const Vector<String>& domainsToBlock, const Vector<String>& domainsToNeitherPartitionNorBlock, bool clearFirst);
     WEBCORE_EXPORT void removePrevalentDomains(const Vector<String>& domains);

Modified: trunk/Source/WebKit/ChangeLog (230001 => 230002)


--- trunk/Source/WebKit/ChangeLog	2018-03-27 19:30:59 UTC (rev 230001)
+++ trunk/Source/WebKit/ChangeLog	2018-03-27 20:27:55 UTC (rev 230002)
@@ -1,3 +1,28 @@
+2018-03-27  Brent Fulgham  <bfulg...@apple.com>
+
+        Further refine cookie read/write logging
+        https://bugs.webkit.org/show_bug.cgi?id=184044
+        <rdar://problem/38915610>
+
+        Reviewed by Chris Dumez.
+
+        Cookie logging was passing the partition, rather than the first party, when logging, which
+        prevented logging in cases where partitioning or blocking was active. This patch corrects
+        these calls so that logging is generated in these cases, too.
+
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::NetworkConnectionToWebProcess::cookiesForDOM): Call log routines if needed.
+        (WebKit::NetworkConnectionToWebProcess::setCookiesFromDOM): Ditto.
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::escapeIDForJSON): Make available to use in multiple functions.
+        (WebKit::NetworkResourceLoader::logCookieInformation const): Revise to use shared
+        convenience functions.
+        (WebKit::logBlockedCookieInformation): Added.
+        (WebKit::logCookieInformationInternal): Added.
+        (WebKit::NetworkResourceLoader::logCookieInformation): Revise to use shared
+        convenience functions.
+        * NetworkProcess/NetworkResourceLoader.h:
+
 2018-03-27  Brian Burg  <bb...@apple.com>
 
         Web Automation: support enter/exit fullscreen and hide/restore window operations

Modified: trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp (230001 => 230002)


--- trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp	2018-03-27 19:30:59 UTC (rev 230001)
+++ trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp	2018-03-27 20:27:55 UTC (rev 230002)
@@ -338,7 +338,12 @@
 
 void NetworkConnectionToWebProcess::cookiesForDOM(PAL::SessionID sessionID, const URL& firstParty, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies, String& cookieString, bool& secureCookiesAccessed)
 {
-    std::tie(cookieString, secureCookiesAccessed) = WebCore::cookiesForDOM(storageSession(sessionID), firstParty, url, frameID, pageID, includeSecureCookies);
+    auto& networkStorageSession = storageSession(sessionID);
+    std::tie(cookieString, secureCookiesAccessed) = WebCore::cookiesForDOM(networkStorageSession, firstParty, url, frameID, pageID, includeSecureCookies);
+#if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
+    if (NetworkProcess::singleton().shouldLogCookieInformation())
+        NetworkResourceLoader::logCookieInformation("NetworkConnectionToWebProcess::cookiesForDOM", reinterpret_cast<const void*>(this), networkStorageSession, firstParty, url, emptyString(), frameID, pageID, std::nullopt);
+#endif
 }
 
 void NetworkConnectionToWebProcess::setCookiesFromDOM(PAL::SessionID sessionID, const URL& firstParty, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, const String& cookieString)
@@ -346,10 +351,8 @@
     auto& networkStorageSession = storageSession(sessionID);
     WebCore::setCookiesFromDOM(networkStorageSession, firstParty, url, frameID, pageID, cookieString);
 #if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
-    if (NetworkProcess::singleton().shouldLogCookieInformation()) {
-        auto partition = WebCore::URL(ParsedURLString, networkStorageSession.cookieStoragePartition(firstParty, url, frameID, pageID));
-        NetworkResourceLoader::logCookieInformation("NetworkConnectionToWebProcess::setCookiesFromDOM", reinterpret_cast<const void*>(this), networkStorageSession, partition, url, emptyString(), frameID, pageID, std::nullopt);
-    }
+    if (NetworkProcess::singleton().shouldLogCookieInformation())
+        NetworkResourceLoader::logCookieInformation("NetworkConnectionToWebProcess::setCookiesFromDOM", reinterpret_cast<const void*>(this), networkStorageSession, firstParty, url, emptyString(), frameID, pageID, std::nullopt);
 #endif
 }
 

Modified: trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp (230001 => 230002)


--- trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp	2018-03-27 19:30:59 UTC (rev 230001)
+++ trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp	2018-03-27 20:27:55 UTC (rev 230002)
@@ -740,6 +740,11 @@
     return s.replace('\\', "\\\\").replace('"', "\\\"");
 }
 
+static String escapeIDForJSON(const std::optional<uint64_t>& value)
+{
+    return value ? String::number(value.value()) : String("None");
+};
+
 void NetworkResourceLoader::logCookieInformation() const
 {
     ASSERT(shouldLogCookieInformation());
@@ -747,39 +752,42 @@
     auto networkStorageSession = WebCore::NetworkStorageSession::storageSession(sessionID());
     ASSERT(networkStorageSession);
 
+    logCookieInformation("NetworkResourceLoader", reinterpret_cast<const void*>(this), *networkStorageSession, originalRequest().firstPartyForCookies(), originalRequest().url(), originalRequest().httpReferrer(), frameID(), pageID(), identifier());
+}
+
+static void logBlockedCookieInformation(const String& label, const void* loggedObject, const WebCore::NetworkStorageSession& networkStorageSession, const WebCore::URL& firstParty, const WebCore::URL& url, const String& referrer, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, std::optional<uint64_t> identifier)
+{
+    ASSERT(NetworkResourceLoader::shouldLogCookieInformation());
+
+    auto escapedURL = escapeForJSON(url.string());
+    auto escapedFirstParty = escapeForJSON(firstParty.string());
+    auto escapedFrameID = escapeIDForJSON(frameID);
+    auto escapedPageID = escapeIDForJSON(pageID);
+    auto escapedIdentifier = escapeIDForJSON(identifier);
+    auto escapedReferrer = escapeForJSON(referrer);
+
+#define LOCAL_LOG_IF_ALLOWED(fmt, ...) RELEASE_LOG_IF(networkStorageSession.sessionID().isAlwaysOnLoggingAllowed(), Network, "%p - %s::" fmt, loggedObject, label.utf8().data(), ##__VA_ARGS__)
 #define LOCAL_LOG(str, ...) \
-    RELEASE_LOG_IF_ALLOWED("logCookieInformation: pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ": " str, pageID(), frameID(), identifier(), ##__VA_ARGS__)
+    LOCAL_LOG_IF_ALLOWED("logCookieInformation: BLOCKED cookie access for pageID = %s, frameID = %s, resourceID = %s, firstParty = %s: " str, escapedPageID.utf8().data(), escapedFrameID.utf8().data(), escapedIdentifier.utf8().data(), escapedFirstParty.utf8().data(), ##__VA_ARGS__)
 
-    auto url = ""
-    if (networkStorageSession->shouldBlockCookies(originalRequest())) {
-        auto escapedURL = escapeForJSON(url.string());
-        auto escapedReferrer = escapeForJSON(originalRequest().httpReferrer());
-
-        LOCAL_LOG(R"({ "url": "%{public}s",)", escapedURL.utf8().data());
-        LOCAL_LOG(R"(  "partition": "%{public}s",)", "BLOCKED");
-        LOCAL_LOG(R"(  "hasStorageAccess": %{public}s,)", "false");
-        LOCAL_LOG(R"(  "referer": "%{public}s",)", escapedReferrer.utf8().data());
-        LOCAL_LOG(R"(  "cookies": []})");
-        return;
-    }
+    LOCAL_LOG(R"({ "url": "%{public}s",)", escapedURL.utf8().data());
+    LOCAL_LOG(R"(  "partition": "%{public}s",)", "BLOCKED");
+    LOCAL_LOG(R"(  "hasStorageAccess": %{public}s,)", "false");
+    LOCAL_LOG(R"(  "referer": "%{public}s",)", escapedReferrer.utf8().data());
+    LOCAL_LOG(R"(  "cookies": [])");
+    LOCAL_LOG(R"(  "})");
 #undef LOCAL_LOG
-
-    auto partition = WebCore::URL(ParsedURLString, networkStorageSession->cookieStoragePartition(originalRequest(), frameID(), pageID()));
-    NetworkResourceLoader::logCookieInformation("NetworkResourceLoader", reinterpret_cast<const void*>(this), *networkStorageSession, partition, url, originalRequest().httpReferrer(), frameID(), pageID(), identifier());
+#undef LOCAL_LOG_IF_ALLOWED
 }
 
-void NetworkResourceLoader::logCookieInformation(const String& label, const void* loggedObject, const WebCore::NetworkStorageSession& networkStorageSession, const WebCore::URL& partition, const WebCore::URL& url, const String& referrer, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, std::optional<uint64_t> identifier)
+static void logCookieInformationInternal(const String& label, const void* loggedObject, const WebCore::NetworkStorageSession& networkStorageSession, const WebCore::URL& partition, const WebCore::URL& url, const String& referrer, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, std::optional<uint64_t> identifier)
 {
-    ASSERT(shouldLogCookieInformation());
+    ASSERT(NetworkResourceLoader::shouldLogCookieInformation());
 
     Vector<WebCore::Cookie> cookies;
     if (!WebCore::getRawCookies(networkStorageSession, partition, url, frameID, pageID, cookies))
         return;
 
-    auto escapeIDForJSON = [](std::optional<uint64_t> value) {
-        return value ? String::number(value.value()) : String("None");
-    };
-
     auto escapedURL = escapeForJSON(url.string());
     auto escapedPartition = escapeForJSON(partition.string());
     auto escapedReferrer = escapeForJSON(referrer);
@@ -829,6 +837,18 @@
 #undef LOCAL_LOG
 #undef LOCAL_LOG_IF_ALLOWED
 }
+
+void NetworkResourceLoader::logCookieInformation(const String& label, const void* loggedObject, const NetworkStorageSession& networkStorageSession, const URL& firstParty, const URL& url, const String& referrer, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, std::optional<uint64_t> identifier)
+{
+    ASSERT(shouldLogCookieInformation());
+
+    if (networkStorageSession.shouldBlockCookies(firstParty, url))
+        logBlockedCookieInformation(label, loggedObject, networkStorageSession, firstParty, url, referrer, frameID, pageID, identifier);
+    else {
+        auto partition = URL(ParsedURLString, networkStorageSession.cookieStoragePartition(firstParty, url, frameID, pageID));
+        logCookieInformationInternal(label, loggedObject, networkStorageSession, partition, url, referrer, frameID, pageID, identifier);
+    }
+}
 #endif
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.h (230001 => 230002)


--- trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.h	2018-03-27 19:30:59 UTC (rev 230001)
+++ trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.h	2018-03-27 20:27:55 UTC (rev 230002)
@@ -107,7 +107,7 @@
 
 #if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
     static bool shouldLogCookieInformation();
-    static void logCookieInformation(const String& label, const void* loggedObject, const WebCore::NetworkStorageSession&, const WebCore::URL& partition, const WebCore::URL&, const String& referrer, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, std::optional<uint64_t> identifier);
+    static void logCookieInformation(const String& label, const void* loggedObject, const WebCore::NetworkStorageSession&, const WebCore::URL& firstParty, const WebCore::URL&, const String& referrer, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, std::optional<uint64_t> identifier);
 #endif
 
 private:
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to