Changeset 230367 in webkit


Ignore:
Timestamp:
Apr 6, 2018 9:08:50 PM (6 years ago)
Author:
BJ Burg
Message:

REGRESSION(r228371): WebAutomationSession::deleteAllCookies doesn't delete some cookies
https://bugs.webkit.org/show_bug.cgi?id=184334
<rdar://problem/39212863>

Reviewed by Timothy Hatcher.

When WebDriver adds a cookie for 'localhost', it actually uses the domain '.localhost' per RFC.
When deleting cookies, we first fetch all cookies matching the document's hostname, and
then delete them one by one. However, this code path does not add the dot prefix. This causes
no cookies to match the requested domain, and thus none of them are deleted.

  • UIProcess/Automation/WebAutomationSession.cpp:

(WebKit::domainByAddingDotPrefixIfNeeded): Extract this helper method.
(WebKit::WebAutomationSession::addSingleCookie): Use helper method.
(WebKit::WebAutomationSession::deleteAllCookies): Add a dot prefix when
requesting to delete all cookies for a hostname.

Location:
trunk/Source/WebKit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r230365 r230367  
     12018-04-06  Brian Burg  <bburg@apple.com>
     2
     3        REGRESSION(r228371): WebAutomationSession::deleteAllCookies doesn't delete some cookies
     4        https://bugs.webkit.org/show_bug.cgi?id=184334
     5        <rdar://problem/39212863>
     6
     7        Reviewed by Timothy Hatcher.
     8
     9        When WebDriver adds a cookie for 'localhost', it actually uses the domain '.localhost' per RFC.
     10        When deleting cookies, we first fetch all cookies matching the document's hostname, and
     11        then delete them one by one. However, this code path does not add the dot prefix. This causes
     12        no cookies to match the requested domain, and thus none of them are deleted.
     13
     14        * UIProcess/Automation/WebAutomationSession.cpp:
     15        (WebKit::domainByAddingDotPrefixIfNeeded): Extract this helper method.
     16        (WebKit::WebAutomationSession::addSingleCookie): Use helper method.
     17        (WebKit::WebAutomationSession::deleteAllCookies): Add a dot prefix when
     18        requesting to delete all cookies for a hostname.
     19
    1202018-04-06  Youenn Fablet  <youenn@apple.com>
    221
  • trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp

    r230027 r230367  
    12081208}
    12091209
     1210static String domainByAddingDotPrefixIfNeeded(String domain)
     1211{
     1212    if (domain[0] != '.') {
     1213        // RFC 2965: If an explicitly specified value does not start with a dot, the user agent supplies a leading dot.
     1214        // Assume that any host that ends with a digit is trying to be an IP address.
     1215        if (!WebCore::URL::hostIsIPAddress(domain))
     1216            return makeString('.', domain);
     1217    }
     1218   
     1219    return domain;
     1220}
     1221   
    12101222void WebAutomationSession::addSingleCookie(const String& browsingContextHandle, const JSON::Object& cookieObject, Ref<AddSingleCookieCallback>&& callback)
    12111223{
     
    12321244    if (domain.isEmpty())
    12331245        domain = activeURL.host();
    1234     else if (domain[0] != '.') {
    1235         // RFC 2965: If an explicitly specified value does not start with a dot, the user agent supplies a leading dot.
    1236         // Assume that any host that ends with a digit is trying to be an IP address.
    1237         if (!WebCore::URL::hostIsIPAddress(domain))
    1238             domain = makeString('.', domain);
    1239     }
    1240     cookie.domain = domain;
     1246
     1247    cookie.domain = domainByAddingDotPrefixIfNeeded(domain);
    12411248
    12421249    if (!cookieObject.getString(WTF::ASCIILiteral("path"), cookie.path))
     
    12801287
    12811288    WebCookieManagerProxy* cookieManager = m_processPool->supplement<WebCookieManagerProxy>();
    1282     cookieManager->deleteCookiesForHostname(page->websiteDataStore().sessionID(), activeURL.host());
     1289    cookieManager->deleteCookiesForHostname(page->websiteDataStore().sessionID(), domainByAddingDotPrefixIfNeeded(activeURL.host()));
    12831290}
    12841291
Note: See TracChangeset for help on using the changeset viewer.