Title: [230435] releases/WebKitGTK/webkit-2.20/Source/WebKit
Revision
230435
Author
carlo...@webkit.org
Date
2018-04-09 08:47:17 -0700 (Mon, 09 Apr 2018)

Log Message

Merge r230367 - 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: releases/WebKitGTK/webkit-2.20/Source/WebKit/ChangeLog (230434 => 230435)


--- releases/WebKitGTK/webkit-2.20/Source/WebKit/ChangeLog	2018-04-09 15:47:10 UTC (rev 230434)
+++ releases/WebKitGTK/webkit-2.20/Source/WebKit/ChangeLog	2018-04-09 15:47:17 UTC (rev 230435)
@@ -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-03  Carlos Garcia Campos  <cgar...@igalia.com>
 
         ASSERTION FAILED: !m_mainFrame->coreFrame()->loader().frameHasLoaded() || !m_pendingNavigationID when reloading page while a page is loading

Modified: releases/WebKitGTK/webkit-2.20/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp (230434 => 230435)


--- releases/WebKitGTK/webkit-2.20/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp	2018-04-09 15:47:10 UTC (rev 230434)
+++ releases/WebKitGTK/webkit-2.20/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp	2018-04-09 15:47:17 UTC (rev 230435)
@@ -1142,6 +1142,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(ErrorString& errorString, const String& browsingContextHandle, const JSON::Object& cookieObject, Ref<AddSingleCookieCallback>&& callback)
 {
     WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
@@ -1166,14 +1178,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))
         FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(MissingParameter, "The parameter 'path' was not found.");
 
@@ -1214,7 +1221,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