Title: [294238] trunk
Revision
294238
Author
commit-qu...@webkit.org
Date
2022-05-16 09:49:23 -0700 (Mon, 16 May 2022)

Log Message

Use _adoptEffectiveConfiguration instead of a separate NSURLSession without credentials
https://bugs.webkit.org/show_bug.cgi?id=240362

Patch by Alex Christensen <achristen...@webkit.org> on 2022-05-16
Reviewed by Chris Dumez.

Source/WebCore/PAL:

* pal/spi/cf/CFNetworkSPI.h:

Source/WebKit:

* NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
(WebKit::NetworkDataTaskCocoa::NetworkDataTaskCocoa):
* NetworkProcess/cocoa/NetworkSessionCocoa.h:
* NetworkProcess/cocoa/NetworkSessionCocoa.mm:
(WebKit::NetworkSessionCocoa::initializeNSURLSessionsInSet):
(WebKit::SessionSet::initializeEphemeralStatelessSessionIfNeeded):
(WebKit::NetworkSessionCocoa::sessionWrapperForTask):
(WebKit::NetworkSessionCocoa::appBoundSession):
(WebKit::SessionSet::isolatedSession):
(WebKit::NetworkSessionCocoa::invalidateAndCancelSessionSet):

Modified Paths

Diff

Modified: trunk/Source/WebCore/PAL/ChangeLog (294237 => 294238)


--- trunk/Source/WebCore/PAL/ChangeLog	2022-05-16 16:33:38 UTC (rev 294237)
+++ trunk/Source/WebCore/PAL/ChangeLog	2022-05-16 16:49:23 UTC (rev 294238)
@@ -1,3 +1,12 @@
+2022-05-16  Alex Christensen  <achristen...@webkit.org>
+
+        Use _adoptEffectiveConfiguration instead of a separate NSURLSession without credentials
+        https://bugs.webkit.org/show_bug.cgi?id=240362
+
+        Reviewed by Chris Dumez.
+
+        * pal/spi/cf/CFNetworkSPI.h:
+
 2022-05-08  Yusuke Suzuki  <ysuz...@apple.com>
 
         Put ThreadGlobalData in Thread

Modified: trunk/Source/WebCore/PAL/pal/spi/cf/CFNetworkSPI.h (294237 => 294238)


--- trunk/Source/WebCore/PAL/pal/spi/cf/CFNetworkSPI.h	2022-05-16 16:33:38 UTC (rev 294237)
+++ trunk/Source/WebCore/PAL/pal/spi/cf/CFNetworkSPI.h	2022-05-16 16:49:23 UTC (rev 294238)
@@ -280,6 +280,7 @@
 @end
 
 @interface NSURLSessionTask ()
+- (void) _adoptEffectiveConfiguration:(NSURLSessionConfiguration*) newConfiguration;
 - (NSDictionary *)_timingData;
 @property (readwrite, copy) NSString *_pathToDownloadTaskFile;
 @property (copy) NSString *_storagePartitionIdentifier;

Modified: trunk/Source/WebKit/ChangeLog (294237 => 294238)


--- trunk/Source/WebKit/ChangeLog	2022-05-16 16:33:38 UTC (rev 294237)
+++ trunk/Source/WebKit/ChangeLog	2022-05-16 16:49:23 UTC (rev 294238)
@@ -1,3 +1,21 @@
+2022-05-16  Alex Christensen  <achristen...@webkit.org>
+
+        Use _adoptEffectiveConfiguration instead of a separate NSURLSession without credentials
+        https://bugs.webkit.org/show_bug.cgi?id=240362
+
+        Reviewed by Chris Dumez.
+
+        * NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
+        (WebKit::NetworkDataTaskCocoa::NetworkDataTaskCocoa):
+        * NetworkProcess/cocoa/NetworkSessionCocoa.h:
+        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
+        (WebKit::NetworkSessionCocoa::initializeNSURLSessionsInSet):
+        (WebKit::SessionSet::initializeEphemeralStatelessSessionIfNeeded):
+        (WebKit::NetworkSessionCocoa::sessionWrapperForTask):
+        (WebKit::NetworkSessionCocoa::appBoundSession):
+        (WebKit::SessionSet::isolatedSession):
+        (WebKit::NetworkSessionCocoa::invalidateAndCancelSessionSet):
+
 2022-05-13  Michael Catanzaro  <mcatanz...@redhat.com>
 
         [GTK] Warning in WebKitDOMDocumentGtk.cpp with GCC 12

Modified: trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm (294237 => 294238)


--- trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm	2022-05-16 16:33:38 UTC (rev 294237)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm	2022-05-16 16:49:23 UTC (rev 294238)
@@ -356,6 +356,20 @@
 
     m_task = [m_sessionWrapper->session dataTaskWithRequest:nsRequest.get()];
 
+    switch (parameters.storedCredentialsPolicy) {
+    case WebCore::StoredCredentialsPolicy::Use:
+        ASSERT(m_sessionWrapper->session.get().configuration.URLCredentialStorage);
+        break;
+    case WebCore::StoredCredentialsPolicy::EphemeralStateless:
+        ASSERT(!m_sessionWrapper->session.get().configuration.URLCredentialStorage);
+        break;
+    case WebCore::StoredCredentialsPolicy::DoNotUse:
+        NSURLSessionConfiguration *effectiveConfiguration = m_sessionWrapper->session.get().configuration;
+        effectiveConfiguration.URLCredentialStorage = nil;
+        [m_task _adoptEffectiveConfiguration:effectiveConfiguration];
+        break;
+    };
+
     WTFBeginSignpost(m_task.get(), "DataTask", "%{public}s pri: %.2f preconnect: %d", url.string().ascii().data(), toNSURLSessionTaskPriority(request.priority()), parameters.shouldPreconnectOnly == PreconnectOnly::Yes);
 
     RELEASE_ASSERT(!m_sessionWrapper->dataTaskMap.contains([m_task taskIdentifier]));

Modified: trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.h (294237 => 294238)


--- trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.h	2022-05-16 16:33:38 UTC (rev 294237)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.h	2022-05-16 16:49:23 UTC (rev 294238)
@@ -68,7 +68,6 @@
     WTF_MAKE_FAST_ALLOCATED;
 public:
     SessionWrapper sessionWithCredentialStorage;
-    SessionWrapper sessionWithoutCredentialStorage;
     WallTime lastUsed;
 };
 
@@ -87,7 +86,6 @@
     std::unique_ptr<IsolatedSession> appBoundSession;
 
     SessionWrapper sessionWithCredentialStorage;
-    SessionWrapper sessionWithoutCredentialStorage;
     SessionWrapper ephemeralStatelessSession;
 
 private:

Modified: trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm (294237 => 294238)


--- trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm	2022-05-16 16:33:38 UTC (rev 294237)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm	2022-05-16 16:49:23 UTC (rev 294238)
@@ -1351,9 +1351,6 @@
     auto cookieAcceptPolicy = configuration.HTTPCookieStorage.cookieAcceptPolicy;
     LOG(NetworkSession, "Created NetworkSession with cookieAcceptPolicy %lu", cookieAcceptPolicy);
     RELEASE_LOG_IF(cookieAcceptPolicy == NSHTTPCookieAcceptPolicyNever, NetworkSession, "Creating network session with ID %" PRIu64 " that will not accept cookies.", m_sessionID.toUInt64());
-
-    configuration.URLCredentialStorage = nil;
-    sessionSet.sessionWithoutCredentialStorage.initialize(configuration, *this, WebCore::StoredCredentialsPolicy::DoNotUse, NavigatingToAppBoundDomain::No);
 }
 
 SessionSet& NetworkSessionCocoa::sessionSetForPage(WebPageProxyIdentifier webPageProxyID)
@@ -1379,7 +1376,7 @@
         return ephemeralStatelessSession;
 
     NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration];
-    NSURLSessionConfiguration *existingConfiguration = sessionWithoutCredentialStorage.session.get().configuration;
+    NSURLSessionConfiguration *existingConfiguration = sessionWithCredentialStorage.session.get().configuration;
 
     configuration.HTTPCookieAcceptPolicy = NSHTTPCookieAcceptPolicyNever;
     configuration.URLCredentialStorage = nil;
@@ -1423,9 +1420,8 @@
 
     switch (storedCredentialsPolicy) {
     case WebCore::StoredCredentialsPolicy::Use:
+    case WebCore::StoredCredentialsPolicy::DoNotUse:
         return sessionSetForPage(webPageProxyID).sessionWithCredentialStorage;
-    case WebCore::StoredCredentialsPolicy::DoNotUse:
-        return sessionSetForPage(webPageProxyID).sessionWithoutCredentialStorage;
     case WebCore::StoredCredentialsPolicy::EphemeralStateless:
         return initializeEphemeralStatelessSessionIfNeeded(webPageProxyID, NavigatingToAppBoundDomain::No);
     }
@@ -1439,17 +1435,14 @@
     if (!sessionSet.appBoundSession) {
         sessionSet.appBoundSession = makeUnique<IsolatedSession>();
         sessionSet.appBoundSession->sessionWithCredentialStorage.initialize(sessionSet.sessionWithCredentialStorage.session.get().configuration, *this, WebCore::StoredCredentialsPolicy::Use, NavigatingToAppBoundDomain::Yes);
-        sessionSet.appBoundSession->sessionWithoutCredentialStorage.initialize(sessionSet.sessionWithoutCredentialStorage.session.get().configuration, *this, WebCore::StoredCredentialsPolicy::DoNotUse, NavigatingToAppBoundDomain::Yes);
     }
 
     auto& sessionWrapper = [&] (auto storedCredentialsPolicy) -> SessionWrapper& {
         switch (storedCredentialsPolicy) {
         case WebCore::StoredCredentialsPolicy::Use:
-            LOG(NetworkSession, "Using app-bound NSURLSession with credential storage.");
+        case WebCore::StoredCredentialsPolicy::DoNotUse:
+            LOG(NetworkSession, "Using app-bound NSURLSession.");
             return sessionSet.appBoundSession->sessionWithCredentialStorage;
-        case WebCore::StoredCredentialsPolicy::DoNotUse:
-            LOG(NetworkSession, "Using app-bound NSURLSession without credential storage.");
-            return sessionSet.appBoundSession->sessionWithoutCredentialStorage;
         case WebCore::StoredCredentialsPolicy::EphemeralStateless:
             return initializeEphemeralStatelessSessionIfNeeded(webPageProxyID, NavigatingToAppBoundDomain::Yes);
         }
@@ -1488,7 +1481,6 @@
     auto& entry = isolatedSessions.ensure(firstPartyDomain, [this, &session, isNavigatingToAppBoundDomain] {
         auto newEntry = makeUnique<IsolatedSession>();
         newEntry->sessionWithCredentialStorage.initialize(sessionWithCredentialStorage.session.get().configuration, session, WebCore::StoredCredentialsPolicy::Use, isNavigatingToAppBoundDomain);
-        newEntry->sessionWithoutCredentialStorage.initialize(sessionWithoutCredentialStorage.session.get().configuration, session, WebCore::StoredCredentialsPolicy::DoNotUse, isNavigatingToAppBoundDomain);
         return newEntry;
     }).iterator->value;
 
@@ -1497,11 +1489,9 @@
     auto& sessionWrapper = [&] (auto storedCredentialsPolicy) -> SessionWrapper& {
         switch (storedCredentialsPolicy) {
         case WebCore::StoredCredentialsPolicy::Use:
-            LOG(NetworkSession, "Using isolated NSURLSession with credential storage.");
+        case WebCore::StoredCredentialsPolicy::DoNotUse:
+            LOG(NetworkSession, "Using isolated NSURLSession.");
             return entry->sessionWithCredentialStorage;
-        case WebCore::StoredCredentialsPolicy::DoNotUse:
-            LOG(NetworkSession, "Using isolated NSURLSession without credential storage.");
-            return entry->sessionWithoutCredentialStorage;
         case WebCore::StoredCredentialsPolicy::EphemeralStateless:
             return initializeEphemeralStatelessSessionIfNeeded(isNavigatingToAppBoundDomain, session);
         }
@@ -1548,17 +1538,13 @@
 void NetworkSessionCocoa::invalidateAndCancelSessionSet(SessionSet& sessionSet)
 {
     [sessionSet.sessionWithCredentialStorage.session invalidateAndCancel];
-    [sessionSet.sessionWithoutCredentialStorage.session invalidateAndCancel];
     [sessionSet.ephemeralStatelessSession.session invalidateAndCancel];
     [sessionSet.sessionWithCredentialStorage.delegate sessionInvalidated];
-    [sessionSet.sessionWithoutCredentialStorage.delegate sessionInvalidated];
     [sessionSet.ephemeralStatelessSession.delegate sessionInvalidated];
 
     for (auto& session : sessionSet.isolatedSessions.values()) {
         [session->sessionWithCredentialStorage.session invalidateAndCancel];
         [session->sessionWithCredentialStorage.delegate sessionInvalidated];
-        [session->sessionWithoutCredentialStorage.session invalidateAndCancel];
-        [session->sessionWithoutCredentialStorage.delegate sessionInvalidated];
     }
     sessionSet.isolatedSessions.clear();
 
@@ -1565,8 +1551,6 @@
     if (sessionSet.appBoundSession) {
         [sessionSet.appBoundSession->sessionWithCredentialStorage.session invalidateAndCancel];
         [sessionSet.appBoundSession->sessionWithCredentialStorage.delegate sessionInvalidated];
-        [sessionSet.appBoundSession->sessionWithoutCredentialStorage.session invalidateAndCancel];
-        [sessionSet.appBoundSession->sessionWithoutCredentialStorage.delegate sessionInvalidated];
     }
 }
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Preconnect.mm (294237 => 294238)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Preconnect.mm	2022-05-16 16:33:38 UTC (rev 294237)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Preconnect.mm	2022-05-16 16:49:23 UTC (rev 294238)
@@ -87,20 +87,16 @@
     });
     auto webView = adoptNS([WKWebView new]);
 
-    // The preconnect to the server will use the default setting of "use the credential store",
-    // and therefore use the credential-store-blessed NSURLSession.
     [webView _preconnectToServer:server.request().URL];
     Util::run(&anyConnections);
     Util::spinRunLoop(10);
     EXPECT_FALSE(requested);
 
-    // Then this request will *not* use the credential store, therefore using a different NSURLSession
-    // that doesn't know about the above preconnect, triggering a second connection to the server.
     webView.get()._canUseCredentialStorage = NO;
     [webView loadRequest:server.request()];
     Util::run(&requested);
 
-    EXPECT_EQ(connectionCount, 2u);
+    EXPECT_EQ(connectionCount, 1u);
 }
 
 TEST(Preconnect, HTTPS)

Modified: trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm (294237 => 294238)


--- trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm	2022-05-16 16:33:38 UTC (rev 294237)
+++ trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm	2022-05-16 16:49:23 UTC (rev 294238)
@@ -237,7 +237,15 @@
         "Content-Length: 0\r\n"
         "WWW-Authenticate: Basic realm=\"testrealm\"\r\n\r\n"_s;
         connection.send(challengeHeader, [connection] {
-            respondWithOK(connection);
+            connection.receiveHTTPRequest([connection] (Vector<char>&&) {
+                connection.send(
+                    "HTTP/1.1 200 OK\r\n"
+                    "Content-Length: 34\r\n\r\n"
+                    "<script>alert('success!')</script>"_s, [connection] {
+                        respondWithChallengeThenOK(connection);
+                    }
+                );
+            });
         });
     });
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to