Title: [230367] trunk/Source/WebKit
Revision
230367
Author
bb...@apple.com
Date
2018-04-06 21:08:50 -0700 (Fri, 06 Apr 2018)

Log 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.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (230366 => 230367)


--- trunk/Source/WebKit/ChangeLog	2018-04-07 03:56:21 UTC (rev 230366)
+++ trunk/Source/WebKit/ChangeLog	2018-04-07 04:08:50 UTC (rev 230367)
@@ -1,3 +1,22 @@
+2018-04-06  Brian Burg  <bb...@apple.com>
+
+        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.
+
 2018-04-06  Youenn Fablet  <you...@apple.com>
 
         Response headers should be filtered when sent from NetworkProcess to WebProcess

Modified: trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp (230366 => 230367)


--- trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp	2018-04-07 03:56:21 UTC (rev 230366)
+++ trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp	2018-04-07 04:08:50 UTC (rev 230367)
@@ -1207,6 +1207,18 @@
     callback->sendSuccess();
 }
 
+static String domainByAddingDotPrefixIfNeeded(String domain)
+{
+    if (domain[0] != '.') {
+        // RFC 2965: If an explicitly specified value does not start with a dot, the user agent supplies a leading dot.
+        // Assume that any host that ends with a digit is trying to be an IP address.
+        if (!WebCore::URL::hostIsIPAddress(domain))
+            return makeString('.', domain);
+    }
+    
+    return domain;
+}
+    
 void WebAutomationSession::addSingleCookie(const String& browsingContextHandle, const JSON::Object& cookieObject, Ref<AddSingleCookieCallback>&& callback)
 {
     WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
@@ -1231,14 +1243,9 @@
     // Inherit the domain/host from the main frame's URL if it is not explicitly set.
     if (domain.isEmpty())
         domain = activeURL.host();
-    else if (domain[0] != '.') {
-        // RFC 2965: If an explicitly specified value does not start with a dot, the user agent supplies a leading dot.
-        // Assume that any host that ends with a digit is trying to be an IP address.
-        if (!WebCore::URL::hostIsIPAddress(domain))
-            domain = makeString('.', domain);
-    }
-    cookie.domain = domain;
 
+    cookie.domain = domainByAddingDotPrefixIfNeeded(domain);
+
     if (!cookieObject.getString(WTF::ASCIILiteral("path"), cookie.path))
         ASYNC_FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(MissingParameter, "The parameter 'path' was not found.");
 
@@ -1279,7 +1286,7 @@
     ASSERT(activeURL.isValid());
 
     WebCookieManagerProxy* cookieManager = m_processPool->supplement<WebCookieManagerProxy>();
-    cookieManager->deleteCookiesForHostname(page->websiteDataStore().sessionID(), activeURL.host());
+    cookieManager->deleteCookiesForHostname(page->websiteDataStore().sessionID(), domainByAddingDotPrefixIfNeeded(activeURL.host()));
 }
 
 void WebAutomationSession::getSessionPermissions(ErrorString&, RefPtr<JSON::ArrayOf<Inspector::Protocol::Automation::SessionPermissionData>>& out_permissions)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to