Changeset 250354 in webkit


Ignore:
Timestamp:
Sep 25, 2019 12:43:02 PM (5 years ago)
Author:
achristensen@apple.com
Message:

Don't fall back to default session if session can't be found for cookie operations
https://bugs.webkit.org/show_bug.cgi?id=202222

Reviewed by Geoff Garen.

Apparently, during teardown of private browsing sessions, there is sometimes a race condition and cookies from a torn-down session are requested.
In this case, just fail like we do all other operations in this file. Otherwise, it's a breach of privacy.

  • NetworkProcess/NetworkConnectionToWebProcess.cpp:

(WebKit::NetworkConnectionToWebProcess::storageSession):
(WebKit::NetworkConnectionToWebProcess::cookiesForDOM):
(WebKit::NetworkConnectionToWebProcess::setCookiesFromDOM):
(WebKit::NetworkConnectionToWebProcess::cookiesEnabled):
(WebKit::NetworkConnectionToWebProcess::cookieRequestHeaderFieldValue):
(WebKit::NetworkConnectionToWebProcess::getRawCookies):
(WebKit::NetworkConnectionToWebProcess::deleteCookie):

  • NetworkProcess/NetworkConnectionToWebProcess.h:
Location:
trunk/Source/WebKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r250352 r250354  
     12019-09-25  Alex Christensen  <achristensen@webkit.org>
     2
     3        Don't fall back to default session if session can't be found for cookie operations
     4        https://bugs.webkit.org/show_bug.cgi?id=202222
     5
     6        Reviewed by Geoff Garen.
     7
     8        Apparently, during teardown of private browsing sessions, there is sometimes a race condition and cookies from a torn-down session are requested.
     9        In this case, just fail like we do all other operations in this file.  Otherwise, it's a breach of privacy.
     10
     11        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
     12        (WebKit::NetworkConnectionToWebProcess::storageSession):
     13        (WebKit::NetworkConnectionToWebProcess::cookiesForDOM):
     14        (WebKit::NetworkConnectionToWebProcess::setCookiesFromDOM):
     15        (WebKit::NetworkConnectionToWebProcess::cookiesEnabled):
     16        (WebKit::NetworkConnectionToWebProcess::cookieRequestHeaderFieldValue):
     17        (WebKit::NetworkConnectionToWebProcess::getRawCookies):
     18        (WebKit::NetworkConnectionToWebProcess::deleteCookie):
     19        * NetworkProcess/NetworkConnectionToWebProcess.h:
     20
    1212019-09-25  Alex Christensen  <achristensen@webkit.org>
    222
  • trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp

    r250193 r250354  
    495495}
    496496
    497 NetworkStorageSession& NetworkConnectionToWebProcess::storageSession()
    498 {
    499     if (m_sessionID != PAL::SessionID::defaultSessionID()) {
    500         if (auto* storageSession = networkProcess().storageSession(m_sessionID))
    501             return *storageSession;
    502 
    503         // Some requests with private browsing mode requested may still be coming shortly after NetworkProcess was told to destroy its session.
    504         // FIXME: Find a way to track private browsing sessions more rigorously.
     497NetworkStorageSession* NetworkConnectionToWebProcess::storageSession()
     498{
     499    auto* session = networkProcess().storageSession(m_sessionID);
     500    if (!session)
    505501        LOG_ERROR("Non-default storage session was requested, but there was no session for it. Please file a bug unless you just disabled private browsing, in which case it's an expected race.");
    506     }
    507     return networkProcess().defaultStorageSession();
     502    return session;
    508503}
    509504
     
    534529void NetworkConnectionToWebProcess::cookiesForDOM(const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, Optional<FrameIdentifier> frameID, Optional<PageIdentifier> pageID, IncludeSecureCookies includeSecureCookies, CompletionHandler<void(String cookieString, bool secureCookiesAccessed)>&& completionHandler)
    535530{
    536     auto& networkStorageSession = storageSession();
    537     auto result = networkStorageSession.cookiesForDOM(firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
     531    auto* networkStorageSession = storageSession();
     532    if (!networkStorageSession)
     533        return completionHandler({ }, false);
     534    auto result = networkStorageSession->cookiesForDOM(firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
    538535#if ENABLE(RESOURCE_LOAD_STATISTICS) && !RELEASE_LOG_DISABLED
    539536    if (auto* session = networkSession()) {
    540537        if (session->shouldLogCookieInformation())
    541             NetworkResourceLoader::logCookieInformation(*this, "NetworkConnectionToWebProcess::cookiesForDOM", reinterpret_cast<const void*>(this), networkStorageSession, firstParty, sameSiteInfo, url, emptyString(), frameID, pageID, WTF::nullopt);
     538            NetworkResourceLoader::logCookieInformation(*this, "NetworkConnectionToWebProcess::cookiesForDOM", reinterpret_cast<const void*>(this), *networkStorageSession, firstParty, sameSiteInfo, url, emptyString(), frameID, pageID, WTF::nullopt);
    542539    }
    543540#endif
     
    547544void NetworkConnectionToWebProcess::setCookiesFromDOM(const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, Optional<WebCore::FrameIdentifier> frameID, Optional<PageIdentifier> pageID, const String& cookieString)
    548545{
    549     auto& networkStorageSession = storageSession();
    550     networkStorageSession.setCookiesFromDOM(firstParty, sameSiteInfo, url, frameID, pageID, cookieString);
     546    auto* networkStorageSession = storageSession();
     547    if (!networkStorageSession)
     548        return;
     549    networkStorageSession->setCookiesFromDOM(firstParty, sameSiteInfo, url, frameID, pageID, cookieString);
    551550#if ENABLE(RESOURCE_LOAD_STATISTICS) && !RELEASE_LOG_DISABLED
    552551    if (auto* session = networkSession()) {
    553552        if (session->shouldLogCookieInformation())
    554             NetworkResourceLoader::logCookieInformation(*this, "NetworkConnectionToWebProcess::setCookiesFromDOM", reinterpret_cast<const void*>(this), networkStorageSession, firstParty, sameSiteInfo, url, emptyString(), frameID, pageID, WTF::nullopt);
     553            NetworkResourceLoader::logCookieInformation(*this, "NetworkConnectionToWebProcess::setCookiesFromDOM", reinterpret_cast<const void*>(this), *networkStorageSession, firstParty, sameSiteInfo, url, emptyString(), frameID, pageID, WTF::nullopt);
    555554    }
    556555#endif
     
    559558void NetworkConnectionToWebProcess::cookiesEnabled(CompletionHandler<void(bool)>&& completionHandler)
    560559{
    561     completionHandler(storageSession().cookiesEnabled());
     560    auto* networkStorageSession = storageSession();
     561    if (!networkStorageSession)
     562        return completionHandler(false);
     563    completionHandler(networkStorageSession->cookiesEnabled());
    562564}
    563565
    564566void NetworkConnectionToWebProcess::cookieRequestHeaderFieldValue(const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, Optional<FrameIdentifier> frameID, Optional<PageIdentifier> pageID, IncludeSecureCookies includeSecureCookies, CompletionHandler<void(String, bool)>&& completionHandler)
    565567{
    566     auto result = storageSession().cookieRequestHeaderFieldValue(firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
     568    auto* networkStorageSession = storageSession();
     569    if (!networkStorageSession)
     570        return completionHandler({ }, false);
     571    auto result = networkStorageSession->cookieRequestHeaderFieldValue(firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
    567572    completionHandler(WTFMove(result.first), result.second);
    568573}
     
    570575void NetworkConnectionToWebProcess::getRawCookies(const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, Optional<FrameIdentifier> frameID, Optional<PageIdentifier> pageID, CompletionHandler<void(Vector<WebCore::Cookie>&&)>&& completionHandler)
    571576{
     577    auto* networkStorageSession = storageSession();
     578    if (!networkStorageSession)
     579        return completionHandler({ });
    572580    Vector<WebCore::Cookie> result;
    573     storageSession().getRawCookies(firstParty, sameSiteInfo, url, frameID, pageID, result);
     581    networkStorageSession->getRawCookies(firstParty, sameSiteInfo, url, frameID, pageID, result);
    574582    completionHandler(WTFMove(result));
    575583}
     
    577585void NetworkConnectionToWebProcess::deleteCookie(const URL& url, const String& cookieName)
    578586{
    579     storageSession().deleteCookie(url, cookieName);
     587    auto* networkStorageSession = storageSession();
     588    if (!networkStorageSession)
     589        return;
     590    networkStorageSession->deleteCookie(url, cookieName);
    580591}
    581592
  • trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h

    r250193 r250354  
    160160
    161161    void didFinishPreconnection(uint64_t preconnectionIdentifier, const WebCore::ResourceError&);
    162     WebCore::NetworkStorageSession& storageSession();
     162    WebCore::NetworkStorageSession* storageSession();
    163163
    164164    // IPC::Connection::Client
Note: See TracChangeset for help on using the changeset viewer.