Changeset 230002 in webkit


Ignore:
Timestamp:
Mar 27, 2018 1:27:55 PM (6 years ago)
Author:
Brent Fulgham
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:
Location:
trunk/Source
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r230000 r230002  
     12018-03-27  Brent Fulgham  <bfulgham@apple.com>
     2
     3        Further refine cookie read/write logging
     4        https://bugs.webkit.org/show_bug.cgi?id=184044
     5        <rdar://problem/38915610>
     6
     7        Reviewed by Chris Dumez.
     8
     9        Export 'shouldBlockCookies' so that it can be accessed by the WebKit framework.
     10
     11        * platform/network/NetworkStorageSession.h:
     12
    1132018-03-27  Antoine Quint  <graouts@apple.com>
    214
  • trunk/Source/WebCore/platform/network/NetworkStorageSession.h

    r229978 r230002  
    104104    WEBCORE_EXPORT String cookieStoragePartition(const ResourceRequest&, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID) const;
    105105    WEBCORE_EXPORT bool shouldBlockCookies(const ResourceRequest&) const;
    106     bool shouldBlockCookies(const URL& firstPartyForCookies, const URL& resource) const;
     106    WEBCORE_EXPORT bool shouldBlockCookies(const URL& firstPartyForCookies, const URL& resource) const;
    107107    WEBCORE_EXPORT String cookieStoragePartition(const URL& firstPartyForCookies, const URL& resource, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID) const;
    108108    WEBCORE_EXPORT void setPrevalentDomainsToPartitionOrBlockCookies(const Vector<String>& domainsToPartition, const Vector<String>& domainsToBlock, const Vector<String>& domainsToNeitherPartitionNorBlock, bool clearFirst);
  • trunk/Source/WebKit/ChangeLog

    r229998 r230002  
     12018-03-27  Brent Fulgham  <bfulgham@apple.com>
     2
     3        Further refine cookie read/write logging
     4        https://bugs.webkit.org/show_bug.cgi?id=184044
     5        <rdar://problem/38915610>
     6
     7        Reviewed by Chris Dumez.
     8
     9        Cookie logging was passing the partition, rather than the first party, when logging, which
     10        prevented logging in cases where partitioning or blocking was active. This patch corrects
     11        these calls so that logging is generated in these cases, too.
     12
     13        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
     14        (WebKit::NetworkConnectionToWebProcess::cookiesForDOM): Call log routines if needed.
     15        (WebKit::NetworkConnectionToWebProcess::setCookiesFromDOM): Ditto.
     16        * NetworkProcess/NetworkResourceLoader.cpp:
     17        (WebKit::escapeIDForJSON): Make available to use in multiple functions.
     18        (WebKit::NetworkResourceLoader::logCookieInformation const): Revise to use shared
     19        convenience functions.
     20        (WebKit::logBlockedCookieInformation): Added.
     21        (WebKit::logCookieInformationInternal): Added.
     22        (WebKit::NetworkResourceLoader::logCookieInformation): Revise to use shared
     23        convenience functions.
     24        * NetworkProcess/NetworkResourceLoader.h:
     25
    1262018-03-27  Brian Burg  <bburg@apple.com>
    227
  • trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp

    r228551 r230002  
    339339void 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)
    340340{
    341     std::tie(cookieString, secureCookiesAccessed) = WebCore::cookiesForDOM(storageSession(sessionID), firstParty, url, frameID, pageID, includeSecureCookies);
     341    auto& networkStorageSession = storageSession(sessionID);
     342    std::tie(cookieString, secureCookiesAccessed) = WebCore::cookiesForDOM(networkStorageSession, firstParty, url, frameID, pageID, includeSecureCookies);
     343#if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
     344    if (NetworkProcess::singleton().shouldLogCookieInformation())
     345        NetworkResourceLoader::logCookieInformation("NetworkConnectionToWebProcess::cookiesForDOM", reinterpret_cast<const void*>(this), networkStorageSession, firstParty, url, emptyString(), frameID, pageID, std::nullopt);
     346#endif
    342347}
    343348
     
    347352    WebCore::setCookiesFromDOM(networkStorageSession, firstParty, url, frameID, pageID, cookieString);
    348353#if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
    349     if (NetworkProcess::singleton().shouldLogCookieInformation()) {
    350         auto partition = WebCore::URL(ParsedURLString, networkStorageSession.cookieStoragePartition(firstParty, url, frameID, pageID));
    351         NetworkResourceLoader::logCookieInformation("NetworkConnectionToWebProcess::setCookiesFromDOM", reinterpret_cast<const void*>(this), networkStorageSession, partition, url, emptyString(), frameID, pageID, std::nullopt);
    352     }
     354    if (NetworkProcess::singleton().shouldLogCookieInformation())
     355        NetworkResourceLoader::logCookieInformation("NetworkConnectionToWebProcess::setCookiesFromDOM", reinterpret_cast<const void*>(this), networkStorageSession, firstParty, url, emptyString(), frameID, pageID, std::nullopt);
    353356#endif
    354357}
  • trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp

    r229569 r230002  
    741741}
    742742
     743static String escapeIDForJSON(const std::optional<uint64_t>& value)
     744{
     745    return value ? String::number(value.value()) : String("None");
     746};
     747
    743748void NetworkResourceLoader::logCookieInformation() const
    744749{
     
    748753    ASSERT(networkStorageSession);
    749754
     755    logCookieInformation("NetworkResourceLoader", reinterpret_cast<const void*>(this), *networkStorageSession, originalRequest().firstPartyForCookies(), originalRequest().url(), originalRequest().httpReferrer(), frameID(), pageID(), identifier());
     756}
     757
     758static 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)
     759{
     760    ASSERT(NetworkResourceLoader::shouldLogCookieInformation());
     761
     762    auto escapedURL = escapeForJSON(url.string());
     763    auto escapedFirstParty = escapeForJSON(firstParty.string());
     764    auto escapedFrameID = escapeIDForJSON(frameID);
     765    auto escapedPageID = escapeIDForJSON(pageID);
     766    auto escapedIdentifier = escapeIDForJSON(identifier);
     767    auto escapedReferrer = escapeForJSON(referrer);
     768
     769#define LOCAL_LOG_IF_ALLOWED(fmt, ...) RELEASE_LOG_IF(networkStorageSession.sessionID().isAlwaysOnLoggingAllowed(), Network, "%p - %s::" fmt, loggedObject, label.utf8().data(), ##__VA_ARGS__)
    750770#define LOCAL_LOG(str, ...) \
    751     RELEASE_LOG_IF_ALLOWED("logCookieInformation: pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ": " str, pageID(), frameID(), identifier(), ##__VA_ARGS__)
    752 
    753     auto url = originalRequest().url();
    754     if (networkStorageSession->shouldBlockCookies(originalRequest())) {
    755         auto escapedURL = escapeForJSON(url.string());
    756         auto escapedReferrer = escapeForJSON(originalRequest().httpReferrer());
    757 
    758         LOCAL_LOG(R"({ "url": "%{public}s",)", escapedURL.utf8().data());
    759         LOCAL_LOG(R"(  "partition": "%{public}s",)", "BLOCKED");
    760         LOCAL_LOG(R"(  "hasStorageAccess": %{public}s,)", "false");
    761         LOCAL_LOG(R"(  "referer": "%{public}s",)", escapedReferrer.utf8().data());
    762         LOCAL_LOG(R"(  "cookies": []})");
    763         return;
    764     }
     771    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__)
     772
     773    LOCAL_LOG(R"({ "url": "%{public}s",)", escapedURL.utf8().data());
     774    LOCAL_LOG(R"(  "partition": "%{public}s",)", "BLOCKED");
     775    LOCAL_LOG(R"(  "hasStorageAccess": %{public}s,)", "false");
     776    LOCAL_LOG(R"(  "referer": "%{public}s",)", escapedReferrer.utf8().data());
     777    LOCAL_LOG(R"(  "cookies": [])");
     778    LOCAL_LOG(R"(  "})");
    765779#undef LOCAL_LOG
    766 
    767     auto partition = WebCore::URL(ParsedURLString, networkStorageSession->cookieStoragePartition(originalRequest(), frameID(), pageID()));
    768     NetworkResourceLoader::logCookieInformation("NetworkResourceLoader", reinterpret_cast<const void*>(this), *networkStorageSession, partition, url, originalRequest().httpReferrer(), frameID(), pageID(), identifier());
    769 }
    770 
    771 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)
    772 {
    773     ASSERT(shouldLogCookieInformation());
     780#undef LOCAL_LOG_IF_ALLOWED
     781}
     782
     783static 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)
     784{
     785    ASSERT(NetworkResourceLoader::shouldLogCookieInformation());
    774786
    775787    Vector<WebCore::Cookie> cookies;
    776788    if (!WebCore::getRawCookies(networkStorageSession, partition, url, frameID, pageID, cookies))
    777789        return;
    778 
    779     auto escapeIDForJSON = [](std::optional<uint64_t> value) {
    780         return value ? String::number(value.value()) : String("None");
    781     };
    782790
    783791    auto escapedURL = escapeForJSON(url.string());
     
    830838#undef LOCAL_LOG_IF_ALLOWED
    831839}
     840
     841void 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)
     842{
     843    ASSERT(shouldLogCookieInformation());
     844
     845    if (networkStorageSession.shouldBlockCookies(firstParty, url))
     846        logBlockedCookieInformation(label, loggedObject, networkStorageSession, firstParty, url, referrer, frameID, pageID, identifier);
     847    else {
     848        auto partition = URL(ParsedURLString, networkStorageSession.cookieStoragePartition(firstParty, url, frameID, pageID));
     849        logCookieInformationInternal(label, loggedObject, networkStorageSession, partition, url, referrer, frameID, pageID, identifier);
     850    }
     851}
    832852#endif
    833853
  • trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.h

    r229560 r230002  
    108108#if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
    109109    static bool shouldLogCookieInformation();
    110     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);
     110    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);
    111111#endif
    112112
Note: See TracChangeset for help on using the changeset viewer.