Changeset 247162 in webkit


Ignore:
Timestamp:
Jul 5, 2019 9:59:42 AM (5 years ago)
Author:
Ryan Haddad
Message:

Unreviewed, rolling out r247123.

Caused TestWebKitAPI.Challenge.BasicProposedCredential to
fail.

Reverted changeset:

"Only allow fetching and removing session credentials from
WebsiteDataStore"
https://bugs.webkit.org/show_bug.cgi?id=199385
https://trac.webkit.org/changeset/247123

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r247159 r247162  
     12019-07-05  Ryan Haddad  <ryanhaddad@apple.com>
     2
     3        Unreviewed, rolling out r247123.
     4
     5        Caused TestWebKitAPI.Challenge.BasicProposedCredential to
     6        fail.
     7
     8        Reverted changeset:
     9
     10        "Only allow fetching and removing session credentials from
     11        WebsiteDataStore"
     12        https://bugs.webkit.org/show_bug.cgi?id=199385
     13        https://trac.webkit.org/changeset/247123
     14
    1152019-07-05  Youenn Fablet  <youenn@apple.com>
    216
  • trunk/Source/WebCore/platform/network/CredentialStorage.cpp

    r247123 r247162  
    103103}
    104104
    105 HashSet<SecurityOriginData> CredentialStorage::originsWithCredentials() const
     105Vector<SecurityOriginData> CredentialStorage::originsWithCredentials() const
    106106{
    107     HashSet<SecurityOriginData> origins;
     107    Vector<SecurityOriginData> origins;
    108108    for (auto& keyValuePair : m_protectionSpaceToCredentialMap) {
    109109        auto& protectionSpace = keyValuePair.key.second;
     
    130130
    131131        SecurityOriginData origin { protocol, protectionSpace.host(), static_cast<uint16_t>(protectionSpace.port())};
    132         origins.add(WTFMove(origin));
     132        origins.append(WTFMove(origin));
    133133    }
    134134    return origins;
     
    188188}
    189189
    190 #if !PLATFORM(COCOA)
    191 HashSet<SecurityOriginData> CredentialStorage::originsWithSessionCredentials()
    192 {
    193     return { };
    194 }
    195 
    196 void CredentialStorage::removeSessionCredentialsWithOrigins(const Vector<SecurityOriginData>&)
    197 {
    198 }
    199 
    200 void CredentialStorage::clearSessionCredentials()
    201 {
    202 }
    203 #endif
    204 
    205190} // namespace WebCore
  • trunk/Source/WebCore/platform/network/CredentialStorage.h

    r247123 r247162  
    4646    WEBCORE_EXPORT void removeCredentialsWithOrigin(const SecurityOriginData&);
    4747
    48     // OS credential storage.
     48    // OS persistent storage.
    4949    WEBCORE_EXPORT static Credential getFromPersistentStorage(const ProtectionSpace&);
    50     WEBCORE_EXPORT static HashSet<SecurityOriginData> originsWithSessionCredentials();
    51     WEBCORE_EXPORT static void removeSessionCredentialsWithOrigins(const Vector<SecurityOriginData>& origins);
    52     WEBCORE_EXPORT static void clearSessionCredentials();
     50    WEBCORE_EXPORT static Vector<SecurityOriginData> originsWithPersistentCredentials();
    5351
    5452    WEBCORE_EXPORT void clearCredentials();
     
    5957    WEBCORE_EXPORT Credential get(const String&, const URL&);
    6058
    61     WEBCORE_EXPORT HashSet<SecurityOriginData> originsWithCredentials() const;
     59    WEBCORE_EXPORT Vector<SecurityOriginData> originsWithCredentials() const;
    6260
    6361private:
  • trunk/Source/WebCore/platform/network/mac/CredentialStorageMac.mm

    r247123 r247162  
    3939}
    4040
    41 HashSet<SecurityOriginData> CredentialStorage::originsWithSessionCredentials()
     41Vector<WebCore::SecurityOriginData> CredentialStorage::originsWithPersistentCredentials()
    4242{
    43     HashSet<SecurityOriginData> origins;
     43    Vector<WebCore::SecurityOriginData> origins;
    4444    auto allCredentials = [[NSURLCredentialStorage sharedCredentialStorage] allCredentials];
    45     for (NSURLProtectionSpace* key in allCredentials.keyEnumerator) {
    46         for (NSURLProtectionSpace* space in allCredentials) {
    47             auto credentials = allCredentials[space];
    48             for (NSString* user in credentials) {
    49                 if (credentials[user].persistence == NSURLCredentialPersistenceForSession) {
    50                     origins.add(WebCore::SecurityOriginData { String(key.protocol), String(key.host), key.port });
    51                     break;
    52                 }
    53             }
    54         }
    55     }
     45    for (NSURLProtectionSpace* key in allCredentials.keyEnumerator)
     46        origins.append(WebCore::SecurityOriginData { String(key.protocol), String(key.host), key.port });
    5647    return origins;
    5748}
    5849
    59 void CredentialStorage::removeSessionCredentialsWithOrigins(const Vector<SecurityOriginData>& origins)
    60 {
    61     auto sharedStorage = [NSURLCredentialStorage sharedCredentialStorage];
    62     auto allCredentials = [sharedStorage allCredentials];
    63     for (auto& origin : origins) {
    64         for (NSURLProtectionSpace* space in allCredentials) {
    65             if (origin.protocol == String(space.protocol)
    66                 && origin.host == String(space.host)
    67                 && origin.port
    68                 && *origin.port == space.port) {
    69                     auto credentials = allCredentials[space];
    70                     for (NSString* user in credentials) {
    71                         auto credential = credentials[user];
    72                         if (credential.persistence == NSURLCredentialPersistenceForSession)
    73                             [sharedStorage removeCredential:credential forProtectionSpace:space];
    74                 }
    75             }
    76         }
    77     }
    78 }
    79 
    80 void CredentialStorage::clearSessionCredentials()
    81 {
    82     auto sharedStorage = [NSURLCredentialStorage sharedCredentialStorage];
    83     auto allCredentials = [sharedStorage allCredentials];
    84     for (NSURLProtectionSpace* space in allCredentials.keyEnumerator) {
    85         auto credentials = allCredentials[space];
    86         for (NSString* user in credentials) {
    87             auto credential = credentials[user];
    88             if (credential.persistence == NSURLCredentialPersistenceForSession)
    89                 [sharedStorage removeCredential:credential forProtectionSpace:space];
    90         }
    91     }
    92 }
    93 
    9450} // namespace WebCore
  • trunk/Source/WebKit/ChangeLog

    r247161 r247162  
     12019-07-05  Ryan Haddad  <ryanhaddad@apple.com>
     2
     3        Unreviewed, rolling out r247123.
     4
     5        Caused TestWebKitAPI.Challenge.BasicProposedCredential to
     6        fail.
     7
     8        Reverted changeset:
     9
     10        "Only allow fetching and removing session credentials from
     11        WebsiteDataStore"
     12        https://bugs.webkit.org/show_bug.cgi?id=199385
     13        https://trac.webkit.org/changeset/247123
     14
    1152019-07-05  Wenson Hsieh  <wenson_hsieh@apple.com>
    216
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp

    r247123 r247162  
    12991299                callbackAggregator->m_websiteData.entries.append({ securityOrigin, WebsiteDataType::Credentials, 0 });
    13001300        }
    1301         auto securityOrigins = WebCore::CredentialStorage::originsWithSessionCredentials();
    1302         for (auto& securityOrigin : securityOrigins)
    1303             callbackAggregator->m_websiteData.entries.append({ securityOrigin, WebsiteDataType::Credentials, 0 });
    13041301    }
    13051302
     
    13831380        if (auto* session = storageSession(sessionID))
    13841381            session->credentialStorage().clearCredentials();
    1385         WebCore::CredentialStorage::clearSessionCredentials();
    13861382    }
    13871383
     
    15211517                session->credentialStorage().removeCredentialsWithOrigin(originData);
    15221518        }
    1523         WebCore::CredentialStorage::removeSessionCredentialsWithOrigins(originDatas);
    15241519    }
    15251520
     
    16661661#endif
    16671662
     1663    /*
     1664    // FIXME: No API to delete credentials by origin
     1665    HashSet<String> originsWithCredentials;
    16681666    if (websiteDataTypes.contains(WebsiteDataType::Credentials)) {
    1669         if (auto* session = storageSession(sessionID)) {
    1670             auto origins = session->credentialStorage().originsWithCredentials();
    1671             auto originsToDelete = filterForRegistrableDomains(origins, domainsToDeleteAllButCookiesFor, callbackAggregator->m_domains);
    1672             for (auto& origin : originsToDelete)
    1673                 session->credentialStorage().removeCredentialsWithOrigin(origin);
    1674         }
    1675 
    1676         auto origins = WebCore::CredentialStorage::originsWithSessionCredentials();
    1677         auto originsToDelete = filterForRegistrableDomains(origins, domainsToDeleteAllButCookiesFor, callbackAggregator->m_domains);
    1678         WebCore::CredentialStorage::removeSessionCredentialsWithOrigins(originsToDelete);
    1679     }
     1667        if (storageSession(sessionID))
     1668            originsWithCredentials = storageSession(sessionID)->credentialStorage().originsWithCredentials();
     1669    }
     1670    */
    16801671   
    16811672    if (websiteDataTypes.contains(WebsiteDataType::DOMCache)) {
     
    25732564
    25742565#if !PLATFORM(COCOA)
     2566void NetworkProcess::originsWithPersistentCredentials(CompletionHandler<void(Vector<WebCore::SecurityOriginData>)>&& completionHandler)
     2567{
     2568    completionHandler(Vector<WebCore::SecurityOriginData>());
     2569}
     2570
     2571void NetworkProcess::removeCredentialsWithOrigins(const Vector<WebCore::SecurityOriginData>&, CompletionHandler<void()>&& completionHandler)
     2572{
     2573    completionHandler();
     2574}
     2575
    25752576void NetworkProcess::initializeProcess(const AuxiliaryProcessInitializationParameters&)
    25762577{
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.h

    r247123 r247162  
    437437
    438438    void platformSyncAllCookies(CompletionHandler<void()>&&);
     439
     440    void originsWithPersistentCredentials(CompletionHandler<void(Vector<WebCore::SecurityOriginData>)>&&);
     441    void removeCredentialsWithOrigins(const Vector<WebCore::SecurityOriginData>& origins, CompletionHandler<void()>&&);
    439442   
    440443    void registerURLSchemeAsSecure(const String&) const;
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in

    r247123 r247162  
    169169    SetAdClickAttributionConversionURLForTesting(PAL::SessionID sessionID, URL url) -> () Async
    170170    MarkAdClickAttributionsAsExpiredForTesting(PAL::SessionID sessionID) -> () Async
     171    OriginsWithPersistentCredentials() -> (Vector<WebCore::SecurityOriginData> origins) Async
     172    RemoveCredentialsWithOrigins(Vector<WebCore::SecurityOriginData> origins) -> () Async
    171173    GetLocalStorageOriginDetails(PAL::SessionID sessionID) -> (Vector<WebKit::LocalStorageDatabaseTracker::OriginDetails> details) Async
    172174}
  • trunk/Source/WebKit/NetworkProcess/cocoa/NetworkProcessCocoa.mm

    r247123 r247162  
    213213}
    214214
     215void NetworkProcess::originsWithPersistentCredentials(CompletionHandler<void(Vector<WebCore::SecurityOriginData>)>&& completionHandler)
     216{
     217    completionHandler(WebCore::CredentialStorage::originsWithPersistentCredentials());
     218}
     219
     220void NetworkProcess::removeCredentialsWithOrigins(const Vector<WebCore::SecurityOriginData>& origins, CompletionHandler<void()>&& completionHandler)
     221{
     222    for (auto& origin : origins) {
     223        auto allCredentials = [[NSURLCredentialStorage sharedCredentialStorage] allCredentials];
     224        for (NSURLProtectionSpace* space in allCredentials) {
     225            if (origin.protocol == String(space.protocol)
     226                && origin.host == String(space.host)
     227                && origin.port
     228                && *origin.port == space.port) {
     229                auto credentials = allCredentials[space];
     230                for (NSString* user in credentials) {
     231                    auto credential = credentials[user];
     232                    [[NSURLCredentialStorage sharedCredentialStorage] removeCredential:credential forProtectionSpace:space];
     233                }
     234            }
     235        }
     236    }
     237    completionHandler();
     238}
     239
    215240#if PLATFORM(MAC)
    216241void NetworkProcess::setSharedHTTPCookieStorage(const Vector<uint8_t>& identifier)
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp

    r247146 r247162  
    521521    }
    522522
     523#if PLATFORM(COCOA)
     524    if (dataTypes.contains(WebsiteDataType::Credentials) && isPersistent()) {
     525        for (auto& processPool : processPools()) {
     526            if (!processPool->networkProcess())
     527                continue;
     528           
     529            callbackAggregator->addPendingCallback();
     530            WTF::CompletionHandler<void(Vector<WebCore::SecurityOriginData>&&)> completionHandler = [callbackAggregator](Vector<WebCore::SecurityOriginData>&& origins) mutable {
     531                WebsiteData websiteData;
     532                for (auto& origin : origins)
     533                    websiteData.entries.append(WebsiteData::Entry { origin, WebsiteDataType::Credentials, 0 });
     534                callbackAggregator->removePendingCallback(WTFMove(websiteData));
     535            };
     536            processPool->networkProcess()->sendWithAsyncReply(Messages::NetworkProcess::OriginsWithPersistentCredentials(), WTFMove(completionHandler));
     537        }
     538    }
     539#endif
     540
    523541#if ENABLE(NETSCAPE_PLUGIN_API)
    524542    if (dataTypes.contains(WebsiteDataType::PlugInData) && isPersistent()) {
     
    627645        processAccessType = std::max(processAccessType, ProcessAccessType::OnlyIfLaunched);
    628646
     647    if (dataTypes.contains(WebsiteDataType::Credentials))
     648        processAccessType = std::max(processAccessType, ProcessAccessType::OnlyIfLaunched);
     649
    629650    return processAccessType;
    630651}
     
    10731094    }
    10741095
     1096    if (dataTypes.contains(WebsiteDataType::Credentials) && isPersistent()) {
     1097        for (auto& processPool : processPools()) {
     1098            if (!processPool->networkProcess())
     1099                continue;
     1100           
     1101            callbackAggregator->addPendingCallback();
     1102            WTF::CompletionHandler<void()> completionHandler = [callbackAggregator]() mutable {
     1103                callbackAggregator->removePendingCallback();
     1104            };
     1105            processPool->networkProcess()->sendWithAsyncReply(Messages::NetworkProcess::RemoveCredentialsWithOrigins(origins), WTFMove(completionHandler));
     1106        }
     1107    }
     1108
    10751109#if ENABLE(NETSCAPE_PLUGIN_API)
    10761110    if (dataTypes.contains(WebsiteDataType::PlugInData) && isPersistent()) {
  • trunk/Tools/ChangeLog

    r247158 r247162  
     12019-07-05  Ryan Haddad  <ryanhaddad@apple.com>
     2
     3        Unreviewed, rolling out r247123.
     4
     5        Caused TestWebKitAPI.Challenge.BasicProposedCredential to
     6        fail.
     7
     8        Reverted changeset:
     9
     10        "Only allow fetching and removing session credentials from
     11        WebsiteDataStore"
     12        https://bugs.webkit.org/show_bug.cgi?id=199385
     13        https://trac.webkit.org/changeset/247123
     14
    1152019-07-05  Wenson Hsieh  <wenson_hsieh@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm

    r247123 r247162  
    9393    readyToContinue = false;
    9494    [[WKWebsiteDataStore defaultDataStore] fetchDataRecordsOfTypes:[WKWebsiteDataStore _allWebsiteDataTypesIncludingPrivate] completionHandler:^(NSArray<WKWebsiteDataRecord *> *dataRecords) {
    95         EXPECT_EQ(0u, dataRecords.count);
     95        ASSERT_EQ(0u, dataRecords.count);
    9696        readyToContinue = true;
    9797    }];
     
    140140{
    141141    TCPServer server(TCPServer::respondWithChallengeThenOK);
    142 
     142   
    143143    usePersistentCredentialStorage = true;
    144144    auto websiteDataStore = [WKWebsiteDataStore defaultDataStore];
     
    152152    [websiteDataStore fetchDataRecordsOfTypes:[NSSet setWithObject:_WKWebsiteDataTypeCredentials] completionHandler:^(NSArray<WKWebsiteDataRecord *> *dataRecords) {
    153153        int credentialCount = dataRecords.count;
    154         EXPECT_EQ(credentialCount, 0);
     154        ASSERT_GT(credentialCount, 0);
     155        bool foundExpectedRecord = false;
     156        for (WKWebsiteDataRecord *record in dataRecords) {
     157            auto name = [record displayName];
     158            if ([name isEqualToString:@"127.0.0.1"]) {
     159                foundExpectedRecord = true;
     160                break;
     161            }
     162        }
     163        EXPECT_TRUE(foundExpectedRecord);
     164        done = true;
     165    }];
     166    TestWebKitAPI::Util::run(&done);
     167   
     168    __block bool removedCredential = false;
     169    [websiteDataStore fetchDataRecordsOfTypes:[NSSet setWithObject:_WKWebsiteDataTypeCredentials] completionHandler:^(NSArray<WKWebsiteDataRecord *> *dataRecords) {
     170        [websiteDataStore removeDataOfTypes:[NSSet setWithObject:_WKWebsiteDataTypeCredentials] forDataRecords:dataRecords completionHandler:^(void) {
     171            removedCredential = true;
     172        }];
     173    }];
     174    TestWebKitAPI::Util::run(&removedCredential);
     175}
     176
     177TEST(WKWebsiteDataStore, RemovePersistentCredentials)
     178{
     179    TCPServer server(TCPServer::respondWithChallengeThenOK);
     180
     181    usePersistentCredentialStorage = true;
     182    auto websiteDataStore = [WKWebsiteDataStore defaultDataStore];
     183    auto navigationDelegate = adoptNS([[NavigationTestDelegate alloc] init]);
     184    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
     185    [webView setNavigationDelegate:navigationDelegate.get()];
     186    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://127.0.0.1:%d/", server.port()]]]];
     187    [navigationDelegate waitForDidFinishNavigation];
     188
     189    __block bool done = false;
     190    __block RetainPtr<WKWebsiteDataRecord> expectedRecord;
     191    [websiteDataStore fetchDataRecordsOfTypes:[NSSet setWithObject:_WKWebsiteDataTypeCredentials] completionHandler:^(NSArray<WKWebsiteDataRecord *> *dataRecords) {
     192        int credentialCount = dataRecords.count;
     193        ASSERT_GT(credentialCount, 0);
     194        for (WKWebsiteDataRecord *record in dataRecords) {
     195            auto name = [record displayName];
     196            if ([name isEqualToString:@"127.0.0.1"]) {
     197                expectedRecord = record;
     198                break;
     199            }
     200        }
     201        EXPECT_TRUE(expectedRecord);
     202        done = true;
     203    }];
     204    TestWebKitAPI::Util::run(&done);
     205
     206    done = false;
     207    [websiteDataStore removeDataOfTypes:[NSSet setWithObject:_WKWebsiteDataTypeCredentials] forDataRecords:[NSArray arrayWithObject:expectedRecord.get()] completionHandler:^(void) {
     208        done = true;
     209    }];
     210    TestWebKitAPI::Util::run(&done);
     211
     212    done = false;
     213    [websiteDataStore fetchDataRecordsOfTypes:[NSSet setWithObject:_WKWebsiteDataTypeCredentials] completionHandler:^(NSArray<WKWebsiteDataRecord *> *dataRecords) {
     214        bool foundLocalHostRecord = false;
     215        for (WKWebsiteDataRecord *record in dataRecords) {
     216            auto name = [record displayName];
     217            if ([name isEqualToString:@"127.0.0.1"]) {
     218                foundLocalHostRecord = true;
     219                break;
     220            }
     221        }
     222        EXPECT_FALSE(foundLocalHostRecord);
    155223        done = true;
    156224    }];
Note: See TracChangeset for help on using the changeset viewer.