From a74a2aa8b3d380b36106b35a2c97940a855973d5 Mon Sep 17 00:00:00 2001 From: brennobemoura <37243584+brennobemoura@users.noreply.github.com> Date: Tue, 18 Aug 2026 17:26:25 -0300 Subject: [PATCH] Avoid iOS 16 URL parsing crash in stringWithUserAndPasswordStripped URL.user()/password() (the percent-encoded accessors) share internal parsing code with URL.host(percentEncoded:) on iOS 16, and calling them there can crash inside host parsing even though host is never touched here. Gate the fast path on iOS 17 instead, so iOS 16 falls back to the legacy user/password properties, which don't hit the bug. See https://forums.swift.org/t/70452 for the same crash signature. --- Sources/AsyncHTTPClient/TracingSupport.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/AsyncHTTPClient/TracingSupport.swift b/Sources/AsyncHTTPClient/TracingSupport.swift index ca7cae82c..c57704009 100644 --- a/Sources/AsyncHTTPClient/TracingSupport.swift +++ b/Sources/AsyncHTTPClient/TracingSupport.swift @@ -136,7 +136,12 @@ internal struct HTTPRequestCancellationError: Error {} extension URL { /// Returns the absolute string of `url` with any embedded credentials (username and password) removed to avoid logging secrets. fileprivate var stringWithUserAndPasswordStripped: String? { - if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) { + // NOTE: Deliberately gated on iOS 17 (not the iOS 16 the percent-encoded `user()`/`password()` + // APIs were introduced in). On iOS 16, calling these APIs can crash inside the shared URL + // component parsing code (the trap surfaces in `URL.host(percentEncoded:)` even though `host` + // is never called here) - see https://forums.swift.org/t/70452. The legacy, non-percent-encoded + // `user`/`password` properties below don't hit that bug and are used as a workaround on iOS 16. + if #available(macOS 14.0, iOS 17.0, tvOS 17.0, watchOS 10.0, *) { guard self.user() != nil || self.password() != nil else { return self.absoluteString }