Bug 198854 - -[WKWebsiteDataStore removeDataOfTypes:modifiedSince:completionHandler:] doesn't delete _WKWebsiteDataTypeCredentials
Summary: -[WKWebsiteDataStore removeDataOfTypes:modifiedSince:completionHandler:] does...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Sihui Liu
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-06-14 00:53 PDT by Sihui Liu
Modified: 2019-06-17 18:43 PDT (History)
7 users (show)

See Also:


Attachments
Patch (17.97 KB, patch)
2019-06-14 01:03 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff
Patch (19.24 KB, patch)
2019-06-14 10:14 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff
Patch (19.69 KB, patch)
2019-06-14 14:45 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff
Patch for landing (19.70 KB, patch)
2019-06-17 18:00 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sihui Liu 2019-06-14 00:53:40 PDT
We added removal of persistent credentials for origin in https://bugs.webkit.org/show_bug.cgi?id=197510. We should also support clearing all credentials.
Comment 1 Sihui Liu 2019-06-14 01:03:52 PDT
Created attachment 372113 [details]
Patch
Comment 2 Sihui Liu 2019-06-14 10:14:06 PDT
Created attachment 372126 [details]
Patch
Comment 3 Per Arne Vollan 2019-06-14 11:11:11 PDT
Comment on attachment 372126 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=372126&action=review

I think this looks very good! Leaving the final review to Geoff or Alex, since they are experts in this area :)

> Source/WebCore/ChangeLog:5
> +        -[WKWebsiteDataStore removeDataOfTypes:modifiedSince:completionHandler:] doesn't delete _WKWebsiteDataTypeCredentials
> +        https://bugs.webkit.org/show_bug.cgi?id=198854
> +

Add radar?
Comment 4 Geoffrey Garen 2019-06-14 12:35:48 PDT
Comment on attachment 372126 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=372126&action=review

> Source/WebCore/platform/network/mac/CredentialStorageMac.mm:41
> +Vector<WebCore::SecurityOriginData> CredentialStorage::getOriginsWithPersistentCredentials()

We usually only use "get" in a function name to indicate that it returns its value through an out parameter. So, this should remain "originsWithPersistentCredentials()".

> Source/WebCore/platform/network/mac/CredentialStorageMac.mm:53
> +        auto allCredentials = [[NSURLCredentialStorage sharedCredentialStorage] allCredentials];

You should move this line out of the loop so that you don't have to call it for each origin.

Also, I think this is a memory leak. -allCredentials returns a dictionary by copy. If you don't release the dictionary, it will leak. You can avoid memory leaks by using smart pointers. The best way to use a smart pointer here is probably

    auto allCredentials = adoptNS([[NSURLCredentialStorage sharedCredentialStorage] allCredentials]);

You should also put sharedCredentialStorage in a local variable to avoid re-fetching it.

> Source/WebCore/platform/network/mac/CredentialStorageMac.mm:71
> +    removePersistentCredentialsWithOrigins(getOriginsWithPersistentCredentials());

Can you do something more efficient here, since we don't need to match against a set of origins, and we can just remove all credentials?

> Source/WebKit/NetworkProcess/NetworkProcess.cpp:1285
> +        if (!sessionID.isEphemeral()) {

Why do we avoid returning this data for ephemeral sessions?

> Source/WebKit/NetworkProcess/NetworkProcess.cpp:1369
> +        if (!sessionID.isEphemeral())
> +            WebCore::CredentialStorage::clearPersistentCredentials();

Why do we avoid deleting website data for ephemeral sessions?

> Source/WebKit/NetworkProcess/NetworkProcess.cpp:1508
> +        if (!sessionID.isEphemeral())
> +            WebCore::CredentialStorage::removePersistentCredentialsWithOrigins(originDatas);

Ditto.
Comment 5 Sihui Liu 2019-06-14 12:57:56 PDT
<rdar://problem/51386058>
Comment 6 Sihui Liu 2019-06-14 14:41:39 PDT
(In reply to Geoffrey Garen from comment #4)
> Comment on attachment 372126 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=372126&action=review
> 
> > Source/WebCore/platform/network/mac/CredentialStorageMac.mm:41
> > +Vector<WebCore::SecurityOriginData> CredentialStorage::getOriginsWithPersistentCredentials()
> 
> We usually only use "get" in a function name to indicate that it returns its
> value through an out parameter. So, this should remain
> "originsWithPersistentCredentials()".
> 

Okay.

> > Source/WebCore/platform/network/mac/CredentialStorageMac.mm:53
> > +        auto allCredentials = [[NSURLCredentialStorage sharedCredentialStorage] allCredentials];
> 
> You should move this line out of the loop so that you don't have to call it
> for each origin.
> 
> Also, I think this is a memory leak. -allCredentials returns a dictionary by
> copy. If you don't release the dictionary, it will leak. You can avoid
> memory leaks by using smart pointers. The best way to use a smart pointer
> here is probably
> 
>     auto allCredentials = adoptNS([[NSURLCredentialStorage
> sharedCredentialStorage] allCredentials]);
> 
> You should also put sharedCredentialStorage in a local variable to avoid
> re-fetching it.
> 

Okay.

> > Source/WebCore/platform/network/mac/CredentialStorageMac.mm:71
> > +    removePersistentCredentialsWithOrigins(getOriginsWithPersistentCredentials());
> 
> Can you do something more efficient here, since we don't need to match
> against a set of origins, and we can just remove all credentials?
> 

Since we don't have API for clear all credentials, we can do similar thing as removePersistentCredentialsWithOrigins.

> > Source/WebKit/NetworkProcess/NetworkProcess.cpp:1285
> > +        if (!sessionID.isEphemeral()) {
> 
> Why do we avoid returning this data for ephemeral sessions?
> 
> > Source/WebKit/NetworkProcess/NetworkProcess.cpp:1369
> > +        if (!sessionID.isEphemeral())
> > +            WebCore::CredentialStorage::clearPersistentCredentials();
> 
> Why do we avoid deleting website data for ephemeral sessions?
> 
> > Source/WebKit/NetworkProcess/NetworkProcess.cpp:1508
> > +        if (!sessionID.isEphemeral())
> > +            WebCore::CredentialStorage::removePersistentCredentialsWithOrigins(originDatas);
> 
> Ditto.

This is the old behavior and I didn't change. My understanding is [NSURLCredentialStorage sharedCredentialStorage] is used for credentials shared across different apps(?), and network process keeps a copy of credentials from ephemeral session in memory with maps in WebCore::CredentialStorage.
Comment 7 Sihui Liu 2019-06-14 14:45:38 PDT
Created attachment 372142 [details]
Patch
Comment 8 Geoffrey Garen 2019-06-14 15:01:43 PDT
Comment on attachment 372142 [details]
Patch

r=me
Comment 9 Sihui Liu 2019-06-17 18:00:48 PDT
Created attachment 372306 [details]
Patch for landing
Comment 10 WebKit Commit Bot 2019-06-17 18:43:46 PDT
Comment on attachment 372306 [details]
Patch for landing

Clearing flags on attachment: 372306

Committed r246530: <https://trac.webkit.org/changeset/246530>
Comment 11 WebKit Commit Bot 2019-06-17 18:43:47 PDT
All reviewed patches have been landed.  Closing bug.