Title: [290317] trunk/Source/WebKit
Revision
290317
Author
[email protected]
Date
2022-02-22 10:21:24 -0800 (Tue, 22 Feb 2022)

Log Message

[WebAuthn] Fix lifetime issue on iOS
https://bugs.webkit.org/show_bug.cgi?id=237018
rdar://89206950

Reviewed by Brent Fulgham.

Lifetime issues introduced in a recent refactor of performRequest were causing
replies from WebAuthenticatorCoordinatorProxy_MakeCredentialReply not to make it
back to the web content process. This patch fixes these, allowing requests to proceed.

* UIProcess/WebAuthentication/Cocoa/WebAuthenticatorCoordinatorProxy.mm:
(WebKit::continueAfterRequest):
(WebKit::WebAuthenticatorCoordinatorProxy::performRequest): Deleted.
(WebKit::WebAuthenticatorCoordinatorProxy::isConditionalMediationAvailable): Deleted.
(WebKit::WebAuthenticatorCoordinatorProxy::isUserVerifyingPlatformAuthenticatorAvailable): Deleted.
* UIProcess/WebAuthentication/WebAuthenticatorCoordinatorProxy.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (290316 => 290317)


--- trunk/Source/WebKit/ChangeLog	2022-02-22 17:55:54 UTC (rev 290316)
+++ trunk/Source/WebKit/ChangeLog	2022-02-22 18:21:24 UTC (rev 290317)
@@ -1,3 +1,22 @@
+2022-02-22  J Pascoe  <[email protected]>
+
+        [WebAuthn] Fix lifetime issue on iOS
+        https://bugs.webkit.org/show_bug.cgi?id=237018
+        rdar://89206950
+
+        Reviewed by Brent Fulgham.
+
+        Lifetime issues introduced in a recent refactor of performRequest were causing
+        replies from WebAuthenticatorCoordinatorProxy_MakeCredentialReply not to make it
+        back to the web content process. This patch fixes these, allowing requests to proceed.
+
+        * UIProcess/WebAuthentication/Cocoa/WebAuthenticatorCoordinatorProxy.mm:
+        (WebKit::continueAfterRequest):
+        (WebKit::WebAuthenticatorCoordinatorProxy::performRequest): Deleted.
+        (WebKit::WebAuthenticatorCoordinatorProxy::isConditionalMediationAvailable): Deleted.
+        (WebKit::WebAuthenticatorCoordinatorProxy::isUserVerifyingPlatformAuthenticatorAvailable): Deleted.
+        * UIProcess/WebAuthentication/WebAuthenticatorCoordinatorProxy.h:
+
 2022-02-22  Brent Fulgham  <[email protected]>
 
         Remove an unneeded IOKit property

Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/WebAuthenticatorCoordinatorProxy.mm (290316 => 290317)


--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/WebAuthenticatorCoordinatorProxy.mm	2022-02-22 17:55:54 UTC (rev 290316)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/WebAuthenticatorCoordinatorProxy.mm	2022-02-22 18:21:24 UTC (rev 290317)
@@ -307,101 +307,107 @@
     return result;
 }
 
-void WebAuthenticatorCoordinatorProxy::performRequest(RetainPtr<ASCCredentialRequestContext> requestContext, RequestCompletionHandler&& handler)
+static inline void continueAfterRequest(RetainPtr<id <ASCCredentialProtocol>> credential, RetainPtr<NSError> error, RequestCompletionHandler&& handler)
 {
-    auto proxy = adoptNS([allocASCAgentProxyInstance() init]);
+    AuthenticatorResponseData response = { };
+    AuthenticatorAttachment attachment;
+    ExceptionData exceptionData = { };
 
-    auto completionHandler = makeBlockPtr([handler = WTFMove(handler)](id <ASCCredentialProtocol> credential, NSError *error) mutable {
-        ensureOnMainRunLoop([handler = WTFMove(handler), credential = retainPtr(credential), error = retainPtr(error)] () mutable {
-            AuthenticatorResponseData response;
-            AuthenticatorAttachment attachment;
-            ExceptionData exceptionData;
+    if ([credential isKindOfClass:getASCPlatformPublicKeyCredentialRegistrationClass()]) {
+        attachment = AuthenticatorAttachment::Platform;
+        response.isAuthenticatorAttestationResponse = true;
 
-            if ([credential isKindOfClass:getASCPlatformPublicKeyCredentialRegistrationClass()]) {
-                attachment = AuthenticatorAttachment::Platform;
-                response.isAuthenticatorAttestationResponse = true;
+        ASCPlatformPublicKeyCredentialRegistration *registrationCredential = credential.get();
+        response.rawId = toArrayBuffer(registrationCredential.credentialID);
+        response.attestationObject = toArrayBuffer(registrationCredential.attestationObject);
+    } else if ([credential isKindOfClass:getASCSecurityKeyPublicKeyCredentialRegistrationClass()]) {
+        attachment = AuthenticatorAttachment::CrossPlatform;
+        response.isAuthenticatorAttestationResponse = true;
 
-                ASCPlatformPublicKeyCredentialRegistration *registrationCredential = credential.get();
-                response.rawId = toArrayBuffer(registrationCredential.credentialID);
-                response.attestationObject = toArrayBuffer(registrationCredential.attestationObject);
-            } else if ([credential isKindOfClass:getASCSecurityKeyPublicKeyCredentialRegistrationClass()]) {
-                attachment = AuthenticatorAttachment::CrossPlatform;
-                response.isAuthenticatorAttestationResponse = true;
+        ASCSecurityKeyPublicKeyCredentialRegistration *registrationCredential = credential.get();
+        response.rawId = toArrayBuffer(registrationCredential.credentialID);
+        response.attestationObject = toArrayBuffer(registrationCredential.attestationObject);
+    } else if ([credential isKindOfClass:getASCPlatformPublicKeyCredentialAssertionClass()]) {
+        attachment = AuthenticatorAttachment::Platform;
+        response.isAuthenticatorAttestationResponse = false;
 
-                ASCSecurityKeyPublicKeyCredentialRegistration *registrationCredential = credential.get();
-                response.rawId = toArrayBuffer(registrationCredential.credentialID);
-                response.attestationObject = toArrayBuffer(registrationCredential.attestationObject);
-            } else if ([credential isKindOfClass:getASCPlatformPublicKeyCredentialAssertionClass()]) {
-                attachment = AuthenticatorAttachment::Platform;
-                response.isAuthenticatorAttestationResponse = false;
+        ASCPlatformPublicKeyCredentialAssertion *assertionCredential = credential.get();
+        response.rawId = toArrayBuffer(assertionCredential.credentialID);
+        response.authenticatorData = toArrayBuffer(assertionCredential.authenticatorData);
+        response.signature = toArrayBuffer(assertionCredential.signature);
+        response.userHandle = toArrayBuffer(assertionCredential.userHandle);
+    } else if ([credential isKindOfClass:getASCSecurityKeyPublicKeyCredentialAssertionClass()]) {
+        attachment = AuthenticatorAttachment::CrossPlatform;
+        response.isAuthenticatorAttestationResponse = false;
 
-                ASCPlatformPublicKeyCredentialAssertion *assertionCredential = credential.get();
-                response.rawId = toArrayBuffer(assertionCredential.credentialID);
-                response.authenticatorData = toArrayBuffer(assertionCredential.authenticatorData);
-                response.signature = toArrayBuffer(assertionCredential.signature);
-                response.userHandle = toArrayBuffer(assertionCredential.userHandle);
-            } else if ([credential isKindOfClass:getASCSecurityKeyPublicKeyCredentialAssertionClass()]) {
-                attachment = AuthenticatorAttachment::CrossPlatform;
-                response.isAuthenticatorAttestationResponse = false;
+        ASCSecurityKeyPublicKeyCredentialAssertion *assertionCredential = credential.get();
+        response.rawId = toArrayBuffer(assertionCredential.credentialID);
+        response.authenticatorData = toArrayBuffer(assertionCredential.authenticatorData);
+        response.signature = toArrayBuffer(assertionCredential.signature);
+        response.userHandle = toArrayBuffer(assertionCredential.userHandle);
+    } else {
+        attachment = (AuthenticatorAttachment) 0;
+        ExceptionCode exceptionCode;
+        NSString *errorMessage = nil;
+        if ([error.get().domain isEqualToString:WKErrorDomain]) {
+            exceptionCode = toExceptionCode(error.get().code);
+            errorMessage = error.get().userInfo[NSLocalizedDescriptionKey];
+        } else {
+            exceptionCode = NotAllowedError;
 
-                ASCSecurityKeyPublicKeyCredentialAssertion *assertionCredential = credential.get();
-                response.rawId = toArrayBuffer(assertionCredential.credentialID);
-                response.authenticatorData = toArrayBuffer(assertionCredential.authenticatorData);
-                response.signature = toArrayBuffer(assertionCredential.signature);
-                response.userHandle = toArrayBuffer(assertionCredential.userHandle);
-            } else {
-                attachment = (AuthenticatorAttachment) 0;
-                ExceptionCode exceptionCode;
-                NSString *errorMessage = nil;
-                if ([error.get().domain isEqualToString:WKErrorDomain]) {
-                    exceptionCode = toExceptionCode(error.get().code);
-                    errorMessage = error.get().userInfo[NSLocalizedDescriptionKey];
-                } else {
-                    exceptionCode = NotAllowedError;
+            if ([error.get().domain isEqualToString:ASCAuthorizationErrorDomain] && error.get().code == ASCAuthorizationErrorUserCanceled)
+                errorMessage = @"This request has been cancelled by the user.";
+            else
+                errorMessage = @"Operation failed.";
+        }
 
-                    if ([error.get().domain isEqualToString:ASCAuthorizationErrorDomain] && error.get().code == ASCAuthorizationErrorUserCanceled)
-                        errorMessage = @"This request has been cancelled by the user.";
-                    else
-                        errorMessage = @"Operation failed.";
-                }
+        exceptionData = { exceptionCode, errorMessage };
+    }
 
-                exceptionData = { exceptionCode, errorMessage };
-            }
+    handler(response, attachment, exceptionData);
+}
 
-            handler(response, attachment, exceptionData);
-        });
-    });
-    
+void WebAuthenticatorCoordinatorProxy::performRequest(RetainPtr<ASCCredentialRequestContext> requestContext, RequestCompletionHandler&& handler)
+{
+    auto proxy = adoptNS([allocASCAgentProxyInstance() init]);
 #if PLATFORM(MAC) || PLATFORM(MACCATALYST)
     if ([requestContext respondsToSelector:@selector(requestStyle)] && requestContext.get().requestStyle == ASCredentialRequestStyleAutoFill) {
-        [proxy performAutoFillAuthorizationRequestsForContext:requestContext.get() withCompletionHandler:makeBlockPtr([proxy = WTFMove(proxy), completionHandler = WTFMove(completionHandler)](id <ASCCredentialProtocol> credential, NSError *error) mutable {
-            completionHandler(credential, error);
+        [proxy performAutoFillAuthorizationRequestsForContext:requestContext.get() withCompletionHandler:makeBlockPtr([weakThis = WeakPtr { *this }, proxy = WTFMove(proxy), handler = WTFMove(handler)](id <ASCCredentialProtocol> credential, NSError *error) mutable {
+            ensureOnMainRunLoop([weakThis, handler = WTFMove(handler), proxy = WTFMove(proxy), credential = retainPtr(credential), error = retainPtr(error)] () mutable {
+                if (!weakThis) {
+                    handler({ }, (AuthenticatorAttachment)0, ExceptionData { NotAllowedError, "Operation failed." });
+                    return;
+                }
+                continueAfterRequest(credential, error, WTFMove(handler));
+            });
         }).get()];
         return;
     }
 #endif // PLATFORM(MAC) || PLATFORM(MACCATALYST)
-    
 #if PLATFORM(IOS)
-    [proxy performAuthorizationRequestsForContext:requestContext.get() withCompletionHandler:makeBlockPtr([proxy = WTFMove(proxy), completionHandler = WTFMove(completionHandler)](id <ASCCredentialProtocol> credential, NSError *error) mutable {
-        completionHandler(credential, error);
-    }).get()];
+    [proxy performAuthorizationRequestsForContext:requestContext.get() withCompletionHandler:makeBlockPtr([handler = WTFMove(handler), proxy = WTFMove(proxy)](id <ASCCredentialProtocol> credential, NSError *error) mutable {
+        callOnMainRunLoop([handler = WTFMove(handler), proxy = WTFMove(proxy), credential = retainPtr(credential), error = retainPtr(error)] () mutable {
 #elif PLATFORM(MAC)
     RetainPtr<NSWindow> window = m_webPageProxy.platformWindow();
-    [proxy performAuthorizationRequestsForContext:requestContext.get() withClearanceHandler:makeBlockPtr([weakThis = WeakPtr { *this }, completionHandler = WTFMove(completionHandler), window = WTFMove(window), proxy = WTFMove(proxy)](NSXPCListenerEndpoint *daemonEndpoint, NSError *error) mutable {
-        callOnMainRunLoop([weakThis, completionHandler = WTFMove(completionHandler), window = WTFMove(window), proxy = WTFMove(proxy), daemonEndpoint = retainPtr(daemonEndpoint), error = retainPtr(error)] () mutable {
+    [proxy performAuthorizationRequestsForContext:requestContext.get() withClearanceHandler:makeBlockPtr([weakThis = WeakPtr { *this }, handler = WTFMove(handler), window = WTFMove(window), proxy = WTFMove(proxy)](NSXPCListenerEndpoint *daemonEndpoint, NSError *error) mutable {
+        callOnMainRunLoop([weakThis, handler = WTFMove(handler), window = WTFMove(window), proxy = WTFMove(proxy), daemonEndpoint = retainPtr(daemonEndpoint), error = retainPtr(error)] () mutable {
             if (!weakThis || !daemonEndpoint) {
                 LOG_ERROR("Could not connect to authorization daemon: %@\n", error.get());
-                completionHandler({ }, error.get());
+                handler({ }, (AuthenticatorAttachment)0, ExceptionData { NotAllowedError, "Operation failed." });
                 return;
             }
 
             weakThis->m_presenter = adoptNS([allocASCAuthorizationRemotePresenterInstance() init]);
-            [weakThis->m_presenter presentWithWindow:window.get() daemonEndpoint:daemonEndpoint.get() completionHandler:makeBlockPtr([proxy = WTFMove(proxy), completionHandler = WTFMove(completionHandler)](id <ASCCredentialProtocol> credential, NSError *error) mutable {
-                completionHandler(credential, error);
+            [weakThis->m_presenter presentWithWindow:window.get() daemonEndpoint:daemonEndpoint.get() completionHandler:makeBlockPtr([handler = WTFMove(handler), proxy = WTFMove(proxy)](id <ASCCredentialProtocol> credentialNotRetain, NSError *errorNotRetain) mutable {
+                auto credential = retainPtr(credentialNotRetain);
+                auto error = retainPtr(errorNotRetain);
+#endif
+                continueAfterRequest(credential, error, WTFMove(handler));
+#if PLATFORM(MAC)
             }).get()];
+#endif
         });
     }).get()];
-#endif // PLATFORM(MAC)
 }
 
 void WebAuthenticatorCoordinatorProxy::isConditionalMediationAvailable(QueryCompletionHandler&& handler)

Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/WebAuthenticatorCoordinatorProxy.h (290316 => 290317)


--- trunk/Source/WebKit/UIProcess/WebAuthentication/WebAuthenticatorCoordinatorProxy.h	2022-02-22 17:55:54 UTC (rev 290316)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/WebAuthenticatorCoordinatorProxy.h	2022-02-22 18:21:24 UTC (rev 290317)
@@ -54,6 +54,8 @@
 struct FrameInfoData;
 struct WebAuthenticationRequestData;
 
+using RequestCompletionHandler = CompletionHandler<void(const WebCore::AuthenticatorResponseData&, WebCore::AuthenticatorAttachment, const WebCore::ExceptionData&)>;
+
 class WebAuthenticatorCoordinatorProxy : public IPC::MessageReceiver {
     WTF_MAKE_FAST_ALLOCATED;
     WTF_MAKE_NONCOPYABLE(WebAuthenticatorCoordinatorProxy);
@@ -62,7 +64,6 @@
     ~WebAuthenticatorCoordinatorProxy();
 
 private:
-    using RequestCompletionHandler = CompletionHandler<void(const WebCore::AuthenticatorResponseData&, WebCore::AuthenticatorAttachment, const WebCore::ExceptionData&)>;
     using QueryCompletionHandler = CompletionHandler<void(bool)>;
 
     // IPC::MessageReceiver.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to