From 37235cf38e22ae0e4ec92a5486a11350b96d7551 Mon Sep 17 00:00:00 2001 From: Eli Liebman Date: Thu, 22 Jan 2026 14:05:48 -0500 Subject: [PATCH] Fix authentication challenge completion handler not being called The urlSession(_:didReceive:completionHandler:) method was only calling the completionHandler for NSURLAuthenticationMethodServerTrust challenges when serverTrust was non-nil. This caused other authentication methods (e.g., NSURLAuthenticationMethodClientCertificate) to hang indefinitely as the completionHandler was never invoked. Added fallback to ensure completionHandler is always called with .performDefaultHandling for unhandled cases. --- Sources/NetShears/URLProtocol/NetworkLoggerUrlProtocol.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/NetShears/URLProtocol/NetworkLoggerUrlProtocol.swift b/Sources/NetShears/URLProtocol/NetworkLoggerUrlProtocol.swift index 43f00c9..6e76bf9 100644 --- a/Sources/NetShears/URLProtocol/NetworkLoggerUrlProtocol.swift +++ b/Sources/NetShears/URLProtocol/NetworkLoggerUrlProtocol.swift @@ -124,7 +124,7 @@ extension NetworkLoggerUrlProtocol: URLSessionDataDelegate { func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { let protectionSpace = challenge.protectionSpace let sender = challenge.sender - + if protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust { if let serverTrust = protectionSpace.serverTrust { let credential = URLCredential(trust: serverTrust) @@ -133,6 +133,9 @@ extension NetworkLoggerUrlProtocol: URLSessionDataDelegate { return } } + + sender?.performDefaultHandling?(for: challenge) + completionHandler(.performDefaultHandling, nil) } func urlSessionDidFinishEvents(forBackgroundURLSession session: URLSession) {