Changeset 228111 in webkit


Ignore:
Timestamp:
Feb 5, 2018 12:03:48 PM (6 years ago)
Author:
Brent Fulgham
Message:

Improve NetworkResourceLoader logging so it can be used for 'setCookiesFromDOM'
https://bugs.webkit.org/show_bug.cgi?id=182455
<rdar://problem/36626601>

Reviewed by Chris Dumez.

Source/WebCore:

After this refactoring, a convenience method I added in r227860 is no longer needed.
This patch removes this dead code.

  • platform/network/NetworkStorageSession.h: Export 'cookieStoragePartition' so it can

be used in WebKit.

  • platform/network/cf/NetworkStorageSessionCFNet.cpp:

(WebCore::NetworkStorageSession::hasStorageAccessForFrame): Deleted unused method.

Source/WebKit:

Refactor "logCookieInformation" so that it can be used for resource loads and DOM cookie
manipulation. Place the generally useful logic in a static method that can be invoked
from other places in the NetworkProcess.

Call the new refactored method from NetworkConnectionToWebProcess::setCookiesFromDOM so
we can perform logging there as well.

  • NetworkProcess/NetworkConnectionToWebProcess.cpp:

(WebKit::NetworkConnectionToWebProcess::setCookiesFromDOM): Call the new logging method
(when enabled).

  • NetworkProcess/NetworkResourceLoader.cpp:

(WebKit::NetworkResourceLoader::shouldLogCookieInformation): Changed to static method.
(WebKit::escapeForJSON): Made a static function so it could be shared between multiple
methods.
(WebKit::NetworkResourceLoader::logCookieInformation const): Refactor into two methods.
(WebKit::NetworkResourceLoader::logCookieInformation): Ditto.
(WebKit::NetworkResourceLoader::shouldLogCookieInformation const): Deleted.

  • NetworkProcess/NetworkResourceLoader.h:
  • NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:

(WebKit::NetworkDataTaskCocoa::NetworkDataTaskCocoa): Switch to user-enabled release logging
to track partitioning and blocking behavior.

Location:
trunk/Source
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r228110 r228111  
     12018-02-02  Brent Fulgham  <bfulgham@apple.com>
     2
     3        Improve NetworkResourceLoader logging so it can be used for 'setCookiesFromDOM'
     4        https://bugs.webkit.org/show_bug.cgi?id=182455
     5        <rdar://problem/36626601>
     6
     7        Reviewed by Chris Dumez.
     8
     9        After this refactoring, a convenience method I added in r227860 is no longer needed.
     10        This patch removes this dead code.
     11
     12        * platform/network/NetworkStorageSession.h: Export 'cookieStoragePartition' so it can
     13        be used in WebKit.
     14        * platform/network/cf/NetworkStorageSessionCFNet.cpp:
     15        (WebCore::NetworkStorageSession::hasStorageAccessForFrame): Deleted unused method.
     16
    1172018-02-05  Antti Koivisto  <antti@apple.com>
    218
  • trunk/Source/WebCore/platform/network/NetworkStorageSession.h

    r228109 r228111  
    102102    WEBCORE_EXPORT bool shouldBlockCookies(const ResourceRequest&) const;
    103103    bool shouldBlockCookies(const URL& firstPartyForCookies, const URL& resource) const;
    104     String cookieStoragePartition(const URL& firstPartyForCookies, const URL& resource, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID) const;
     104    WEBCORE_EXPORT String cookieStoragePartition(const URL& firstPartyForCookies, const URL& resource, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID) const;
    105105    WEBCORE_EXPORT void setPrevalentDomainsToPartitionOrBlockCookies(const Vector<String>& domainsToPartition, const Vector<String>& domainsToBlock, const Vector<String>& domainsToNeitherPartitionNorBlock, bool clearFirst);
    106106    WEBCORE_EXPORT void removePrevalentDomains(const Vector<String>& domains);
    107107    WEBCORE_EXPORT bool hasStorageAccessForFrame(const String& resourceDomain, const String& firstPartyDomain, uint64_t frameID, uint64_t pageID) const;
    108     WEBCORE_EXPORT bool hasStorageAccessForFrame(const ResourceRequest&, uint64_t frameID, uint64_t pageID) const;
    109108    WEBCORE_EXPORT Vector<String> getAllStorageAccessEntries() const;
    110109    WEBCORE_EXPORT void grantStorageAccessForFrame(const String& resourceDomain, const String& firstPartyDomain, uint64_t frameID, uint64_t pageID);
  • trunk/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp

    r228109 r228111  
    297297}
    298298
    299 bool NetworkStorageSession::hasStorageAccessForFrame(const ResourceRequest& request, uint64_t frameID, uint64_t pageID) const
    300 {
    301     if (!cookieStoragePartitioningEnabled)
    302         return false;
    303 
    304     return hasStorageAccessForFrame(getPartitioningDomain(request.url()), getPartitioningDomain(request.firstPartyForCookies()), frameID, pageID);
    305 }
    306 
    307299Vector<String> NetworkStorageSession::getAllStorageAccessEntries() const
    308300{
  • trunk/Source/WebKit/ChangeLog

    r228109 r228111  
     12018-02-02  Brent Fulgham  <bfulgham@apple.com>
     2
     3        Improve NetworkResourceLoader logging so it can be used for 'setCookiesFromDOM'
     4        https://bugs.webkit.org/show_bug.cgi?id=182455
     5        <rdar://problem/36626601>
     6
     7        Reviewed by Chris Dumez.
     8
     9        Refactor "logCookieInformation" so that it can be used for resource loads and DOM cookie
     10        manipulation. Place the generally useful logic in a static method that can be invoked
     11        from other places in the NetworkProcess.
     12
     13        Call the new refactored method from NetworkConnectionToWebProcess::setCookiesFromDOM so
     14        we can perform logging there as well.
     15
     16        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
     17        (WebKit::NetworkConnectionToWebProcess::setCookiesFromDOM): Call the new logging method
     18        (when enabled).
     19        * NetworkProcess/NetworkResourceLoader.cpp:
     20        (WebKit::NetworkResourceLoader::shouldLogCookieInformation): Changed to static method.
     21        (WebKit::escapeForJSON): Made a static function so it could be shared between multiple
     22        methods.
     23        (WebKit::NetworkResourceLoader::logCookieInformation const): Refactor into two methods.
     24        (WebKit::NetworkResourceLoader::logCookieInformation): Ditto.
     25        (WebKit::NetworkResourceLoader::shouldLogCookieInformation const): Deleted.
     26        * NetworkProcess/NetworkResourceLoader.h:
     27        * NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
     28        (WebKit::NetworkDataTaskCocoa::NetworkDataTaskCocoa): Switch to user-enabled release logging
     29        to track partitioning and blocking behavior.
     30
    1312018-02-05  John Wilander  <wilander@apple.com>
    232
  • trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp

    r227682 r228111  
    11/*
    2  * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2012-2018 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    343343void NetworkConnectionToWebProcess::setCookiesFromDOM(PAL::SessionID sessionID, const URL& firstParty, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, const String& cookieString)
    344344{
    345     WebCore::setCookiesFromDOM(storageSession(sessionID), firstParty, url, frameID, pageID, cookieString);
     345    auto& networkStorageSession = storageSession(sessionID);
     346    WebCore::setCookiesFromDOM(networkStorageSession, firstParty, url, frameID, pageID, cookieString);
     347#if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
     348    if (NetworkProcess::singleton().shouldLogCookieInformation()) {
     349        auto partition = WebCore::URL(ParsedURLString, networkStorageSession.cookieStoragePartition(firstParty, url, frameID, pageID));
     350        NetworkResourceLoader::logCookieInformation("NetworkConnectionToWebProcess::setCookiesFromDOM", reinterpret_cast<const void*>(this), networkStorageSession, partition, url, emptyString(), frameID, pageID, std::nullopt);
     351    }
     352#endif
    346353}
    347354
  • trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp

    r227991 r228111  
    711711
    712712#if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
    713 bool NetworkResourceLoader::shouldLogCookieInformation() const
     713bool NetworkResourceLoader::shouldLogCookieInformation()
    714714{
    715715    return NetworkProcess::singleton().shouldLogCookieInformation();
     716}
     717
     718static String escapeForJSON(String s)
     719{
     720    return s.replace('\\', "\\\\").replace('"', "\\\"");
    716721}
    717722
     
    725730#define LOCAL_LOG(str, ...) \
    726731    RELEASE_LOG_IF_ALLOWED("logCookieInformation: pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ": " str, pageID(), frameID(), identifier(), ##__VA_ARGS__)
    727 
    728     auto escapeForJSON = [](String s) {
    729         return s.replace('\\', "\\\\").replace('"', "\\\"");
    730     };
    731732
    732733    auto url = originalRequest().url();
     
    742743        return;
    743744    }
     745#undef LOCAL_LOG
    744746
    745747    auto partition = WebCore::URL(ParsedURLString, networkStorageSession->cookieStoragePartition(originalRequest(), frameID(), pageID()));
    746     bool hasStorageAccessForFrame = networkStorageSession->hasStorageAccessForFrame(originalRequest(), frameID(), pageID());
     748    NetworkResourceLoader::logCookieInformation("NetworkResourceLoader", reinterpret_cast<const void*>(this), *networkStorageSession, partition, url, originalRequest().httpReferrer(), frameID(), pageID(), identifier());
     749}
     750
     751void 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)
     752{
     753    ASSERT(shouldLogCookieInformation());
    747754
    748755    Vector<WebCore::Cookie> cookies;
    749     bool result = WebCore::getRawCookies(*networkStorageSession, partition, url, frameID(), pageID(), cookies);
    750 
    751     if (result) {
    752         auto escapedURL = escapeForJSON(url.string());
    753         auto escapedPartition = escapeForJSON(partition.string());
    754         auto escapedReferrer = escapeForJSON(originalRequest().httpReferrer());
    755 
    756         LOCAL_LOG(R"({ "url": "%{public}s",)", escapedURL.utf8().data());
    757         LOCAL_LOG(R"(  "partition": "%{public}s",)", escapedPartition.utf8().data());
    758         LOCAL_LOG(R"(  "hasStorageAccess": %{public}s,)", hasStorageAccessForFrame ? "true" : "false");
    759         LOCAL_LOG(R"(  "referer": "%{public}s",)", escapedReferrer.utf8().data());
    760         LOCAL_LOG(R"(  "cookies": [)");
    761 
    762         auto size = cookies.size();
    763         decltype(size) count = 0;
    764         for (const auto& cookie : cookies) {
    765             const char* trailingComma = ",";
    766             if (++count == size)
    767                 trailingComma = "";
    768 
    769             auto escapedName = escapeForJSON(cookie.name);
    770             auto escapedValue = escapeForJSON(cookie.value);
    771             auto escapedDomain = escapeForJSON(cookie.domain);
    772             auto escapedPath = escapeForJSON(cookie.path);
    773             auto escapedComment = escapeForJSON(cookie.comment);
    774             auto escapedCommentURL = escapeForJSON(cookie.commentURL.string());
    775 
    776             LOCAL_LOG(R"(  { "name": "%{public}s",)", escapedName.utf8().data());
    777             LOCAL_LOG(R"(    "value": "%{public}s",)", escapedValue.utf8().data());
    778             LOCAL_LOG(R"(    "domain": "%{public}s",)", escapedDomain.utf8().data());
    779             LOCAL_LOG(R"(    "path": "%{public}s",)", escapedPath.utf8().data());
    780             LOCAL_LOG(R"(    "created": %f,)", cookie.created);
    781             LOCAL_LOG(R"(    "expires": %f,)", cookie.expires);
    782             LOCAL_LOG(R"(    "httpOnly": %{public}s,)", cookie.httpOnly ? "true" : "false");
    783             LOCAL_LOG(R"(    "secure": %{public}s,)", cookie.secure ? "true" : "false");
    784             LOCAL_LOG(R"(    "session": %{public}s,)", cookie.session ? "true" : "false");
    785             LOCAL_LOG(R"(    "comment": "%{public}s",)", escapedComment.utf8().data());
    786             LOCAL_LOG(R"(    "commentURL": "%{public}s")", escapedCommentURL.utf8().data());
    787             LOCAL_LOG(R"(  }%{public}s)", trailingComma);
    788         }
    789         LOCAL_LOG(R"(]})");
     756    if (!WebCore::getRawCookies(networkStorageSession, partition, url, frameID, pageID, cookies))
     757        return;
     758
     759    auto escapeIDForJSON = [](std::optional<uint64_t> value) {
     760        return value ? String::number(value.value()) : String("None");
     761    };
     762
     763    auto escapedURL = escapeForJSON(url.string());
     764    auto escapedPartition = escapeForJSON(partition.string());
     765    auto escapedReferrer = escapeForJSON(referrer);
     766    auto escapedFrameID = escapeIDForJSON(frameID);
     767    auto escapedPageID = escapeIDForJSON(pageID);
     768    auto escapedIdentifier = escapeIDForJSON(identifier);
     769    bool hasStorageAccessForFrame = (frameID && pageID) ? networkStorageSession.hasStorageAccessForFrame(url.string(), partition.string(), frameID.value(), pageID.value()) : false;
     770
     771#define LOCAL_LOG_IF_ALLOWED(fmt, ...) RELEASE_LOG_IF(networkStorageSession.sessionID().isAlwaysOnLoggingAllowed(), Network, "%p - %s::" fmt, loggedObject, label.utf8().data(), ##__VA_ARGS__)
     772#define LOCAL_LOG(str, ...) \
     773    LOCAL_LOG_IF_ALLOWED("logCookieInformation: pageID = %s, frameID = %s, resourceID = %s: " str, escapedPageID.utf8().data(), escapedFrameID.utf8().data(), escapedIdentifier.utf8().data(), ##__VA_ARGS__)
     774
     775    LOCAL_LOG(R"({ "url": "%{public}s",)", escapedURL.utf8().data());
     776    LOCAL_LOG(R"(  "partition": "%{public}s",)", escapedPartition.utf8().data());
     777    LOCAL_LOG(R"(  "hasStorageAccess": %{public}s,)", hasStorageAccessForFrame ? "true" : "false");
     778    LOCAL_LOG(R"(  "referer": "%{public}s",)", escapedReferrer.utf8().data());
     779    LOCAL_LOG(R"(  "cookies": [)");
     780
     781    auto size = cookies.size();
     782    decltype(size) count = 0;
     783    for (const auto& cookie : cookies) {
     784        const char* trailingComma = ",";
     785        if (++count == size)
     786            trailingComma = "";
     787
     788        auto escapedName = escapeForJSON(cookie.name);
     789        auto escapedValue = escapeForJSON(cookie.value);
     790        auto escapedDomain = escapeForJSON(cookie.domain);
     791        auto escapedPath = escapeForJSON(cookie.path);
     792        auto escapedComment = escapeForJSON(cookie.comment);
     793        auto escapedCommentURL = escapeForJSON(cookie.commentURL.string());
     794
     795        LOCAL_LOG(R"(  { "name": "%{public}s",)", escapedName.utf8().data());
     796        LOCAL_LOG(R"(    "value": "%{public}s",)", escapedValue.utf8().data());
     797        LOCAL_LOG(R"(    "domain": "%{public}s",)", escapedDomain.utf8().data());
     798        LOCAL_LOG(R"(    "path": "%{public}s",)", escapedPath.utf8().data());
     799        LOCAL_LOG(R"(    "created": %f,)", cookie.created);
     800        LOCAL_LOG(R"(    "expires": %f,)", cookie.expires);
     801        LOCAL_LOG(R"(    "httpOnly": %{public}s,)", cookie.httpOnly ? "true" : "false");
     802        LOCAL_LOG(R"(    "secure": %{public}s,)", cookie.secure ? "true" : "false");
     803        LOCAL_LOG(R"(    "session": %{public}s,)", cookie.session ? "true" : "false");
     804        LOCAL_LOG(R"(    "comment": "%{public}s",)", escapedComment.utf8().data());
     805        LOCAL_LOG(R"(    "commentURL": "%{public}s")", escapedCommentURL.utf8().data());
     806        LOCAL_LOG(R"(  }%{public}s)", trailingComma);
     807    }
     808    LOCAL_LOG(R"(]})");
    790809#undef LOCAL_LOG
    791     }
     810#undef LOCAL_LOG_IF_ALLOWED
    792811}
    793812#endif
  • trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.h

    r226226 r228111  
    3737namespace WebCore {
    3838class BlobDataFileReference;
     39class NetworkStorageSession;
    3940class ResourceRequest;
    4041}
     
    104105    bool isAlwaysOnLoggingAllowed() const;
    105106
     107#if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
     108    static bool shouldLogCookieInformation();
     109    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#endif
     111
    106112private:
    107113    NetworkResourceLoader(const NetworkResourceLoadParameters&, NetworkConnectionToWebProcess&, RefPtr<Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad::DelayedReply>&&);
     
    136142
    137143#if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
    138     bool shouldLogCookieInformation() const;
    139144    void logCookieInformation() const;
    140145#endif
  • trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm

    r227364 r228111  
    199199#if HAVE(CFNETWORK_STORAGE_PARTITIONING)
    200200    if (auto shouldBlockCookies = session.networkStorageSession().shouldBlockCookies(request)) {
     201#if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
     202        if (NetworkProcess::singleton().shouldLogCookieInformation())
     203            RELEASE_LOG_IF(m_session->sessionID().isAlwaysOnLoggingAllowed(), Network, "%p - NetworkDataTaskCocoa::logCookieInformation: pageID = %llu, frameID = %llu, taskID = %lu: Blocking cookies for URL %s", this, pageID, frameID, (unsigned long)[m_task taskIdentifier], nsRequest.URL.absoluteString.UTF8String);
     204#else
    201205        LOG(NetworkSession, "%llu Blocking cookies for URL %s", [m_task taskIdentifier], nsRequest.URL.absoluteString.UTF8String);
     206#endif
    202207        applyCookieBlockingPolicy(shouldBlockCookies);
    203208    } else {
    204209        auto storagePartition = session.networkStorageSession().cookieStoragePartition(request, m_frameID, m_pageID);
    205210        if (!storagePartition.isEmpty()) {
     211#if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
     212            if (NetworkProcess::singleton().shouldLogCookieInformation())
     213                RELEASE_LOG_IF(m_session->sessionID().isAlwaysOnLoggingAllowed(), Network, "%p - NetworkDataTaskCocoa::logCookieInformation: pageID = %llu, frameID = %llu, taskID = %lu: Partitioning cookies for URL %s", this, pageID, frameID, (unsigned long)[m_task taskIdentifier], nsRequest.URL.absoluteString.UTF8String);
     214#else
    206215            LOG(NetworkSession, "%llu Partitioning cookies for URL %s", [m_task taskIdentifier], nsRequest.URL.absoluteString.UTF8String);
     216#endif
    207217            applyCookiePartitioningPolicy(storagePartition, emptyString());
    208218        }
Note: See TracChangeset for help on using the changeset viewer.