Bug 184938 - -[WKHTTPCookieStore deleteCookie:completionHandler:] doesn't delete cookies
Summary: -[WKHTTPCookieStore deleteCookie:completionHandler:] doesn't delete cookies
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit API (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Sihui Liu
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-04-24 14:46 PDT by Sihui Liu
Modified: 2018-04-26 14:17 PDT (History)
10 users (show)

See Also:


Attachments
Patch (2.23 KB, patch)
2018-04-24 15:44 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff
Patch (7.95 KB, patch)
2018-04-25 17:45 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff
Patch (7.98 KB, patch)
2018-04-25 19:01 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews200 for win-future (12.66 MB, application/zip)
2018-04-26 03:41 PDT, EWS Watchlist
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sihui Liu 2018-04-24 14:46:33 PDT
There is a method "deleteCookie:completionHandler:" which should delete the specified cookie, but it's not reliable and cookies are not being deleted.
https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882009-deletecookie
Comment 1 Sihui Liu 2018-04-24 14:48:41 PDT
<rdar://problem/34737395>
Comment 2 Sihui Liu 2018-04-24 15:44:32 PDT
Created attachment 338680 [details]
Patch
Comment 3 Sam Weinig 2018-04-24 18:20:01 PDT
Seems like this should have an API test.
Comment 4 Daniel Bates 2018-04-24 19:26:55 PDT
Comment on attachment 338680 [details]
Patch

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

> Source/WebCore/ChangeLog:10
> +        converted to NSHTTPCooike, this property information was lost, and delete function cannot 

NSHTTPCooike => NSHTTPCookie

> Source/WebCore/ChangeLog:14
> +        As existing APIs do not provide a way to create a HTTPOnly cookie, I tested it manually.

Are there any SPIs that we can use to create such a cookie? Maybe this is a dumb question, can we create a custom protocol handler for HTTP and then fabricate a response that includes a Set-Cookie header?
Comment 5 Daniel Bates 2018-04-25 10:56:57 PDT
(In reply to Daniel Bates from comment #4)
> Maybe this is a dumb question, can we create a custom protocol handler for HTTP and then fabricate a response that includes a Set-Cookie header?

This will not work according to Sihui Liu as custom protocol responses are not processed the same way as HTTP responses by CFNetwork.
Comment 6 Sihui Liu 2018-04-25 17:45:35 PDT
Created attachment 338837 [details]
Patch
Comment 7 Sihui Liu 2018-04-25 19:01:44 PDT
Created attachment 338846 [details]
Patch
Comment 8 EWS Watchlist 2018-04-26 03:41:32 PDT
Comment on attachment 338846 [details]
Patch

Attachment 338846 [details] did not pass win-ews (win):
Output: http://webkit-queues.webkit.org/results/7466115

New failing tests:
http/tests/preload/onload_event.html
Comment 9 EWS Watchlist 2018-04-26 03:41:43 PDT
Created attachment 338867 [details]
Archive of layout-test-results from ews200 for win-future

The attached test failures were seen while running run-webkit-tests on the win-ews.
Bot: ews200  Port: win-future  Platform: CYGWIN_NT-6.1-2.9.0-0.318-5-3-x86_64-64bit
Comment 10 Geoffrey Garen 2018-04-26 13:13:45 PDT
Comment on attachment 338846 [details]
Patch

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

r=me

> Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm:70
> +    NSArray *nsCookies = [nsCookieStorage() cookies];
> +    for (NSHTTPCookie *nsCookie in nsCookies) {
> +        if (Cookie(nsCookie) == cookie) {
> +            [nsCookieStorage() deleteCookie:nsCookie];
> +            break;
> +        }
> +    }

Unlike the change to operator== above, which is a nice improvement that we would do intentionally, this change is a purely a workaround, which we'd rather not preserve. So, please do follow up and fix the Cookie => NSHTTPCookie conversion path, and when you do, you can remove this workaround.
Comment 11 WebKit Commit Bot 2018-04-26 13:39:53 PDT
Comment on attachment 338846 [details]
Patch

Clearing flags on attachment: 338846

Committed r231067: <https://trac.webkit.org/changeset/231067>
Comment 12 WebKit Commit Bot 2018-04-26 13:39:55 PDT
All reviewed patches have been landed.  Closing bug.
Comment 13 Daniel Bates 2018-04-26 14:17:06 PDT
Comment on attachment 338846 [details]
Patch

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

> Source/WebCore/platform/network/cocoa/CookieCocoa.mm:146
> +    return name == other.name
> +    && value == other.value
> +    && domain == other.domain
> +    && path == other.path
> +    && created == other.created
> +    && expires == other.expires
> +    && httpOnly == other.httpOnly
> +    && secure == other.secure
> +    && session == other.session
> +    && comment == other.comment
> +    && commentURL == other.commentURL
> +    && ports == other.ports;

This change makes equality testing asymmetric with the hash algorithm as we perform equality testing ourself and ask NSHTTPCookie to compute a hash. The test case included in this patch demonstrates that we know how to set the HttpOnly bit for an NSHTTPCookie; => we can fix the FIXME operator NSHTTPCookie *(). Would it be sufficient to fix this fix me and then revert the change in this function to fix this bug? The benefit of fixing the FIXME and then using -[NSHTTPCookie equal:] is that it makes this class effectively a wrapper for NSHTTPCookie (*) and means there is one less function to modify whenever we need to add a new cookie field.

(*) The class exists for the purpose of exposing a platform-independent interface to a cookie.