Description
When using EventSource through an MITM proxy (e.g., mitmproxy, Charles Proxy), SSE connections fail silently even when the proxy's CA certificate is installed and trusted at the OS level.
Root Cause
SessionDelegate does not implement urlSession(_:didReceive challenge:completionHandler:). While the expected behavior is that URLSession falls back to default system trust evaluation, in practice this can cause the connection to be silently rejected when a custom delegate is set without handling authentication challenges.
Steps to Reproduce
- Install and trust a proxy CA certificate on an iOS device (e.g., mitmproxy CA)
- Configure the device to use the proxy
- Open an SSE connection using EventSource to an HTTPS endpoint
- The connection fails silently — no data events, no error events, the request never reaches the proxy
Expected Behavior
The SSE connection should succeed through the proxy since the CA certificate is installed and trusted at the OS level. URLSession should use the system's default trust evaluation which respects user-installed CA certificates.
Suggested Fix
Add explicit .performDefaultHandling to SessionDelegate:
func urlSession(
_ session: URLSession,
didReceive challenge: URLAuthenticationChallenge,
completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void
) {
completionHandler(.performDefaultHandling, nil)
}
This explicitly delegates to the system's default trust evaluation, which correctly handles user-installed CA certificates. This has no effect on normal (non-proxy) connections.
Environment
- iOS 18
- EventSource (latest from main)
- mitmproxy 11.x
Description
When using EventSource through an MITM proxy (e.g., mitmproxy, Charles Proxy), SSE connections fail silently even when the proxy's CA certificate is installed and trusted at the OS level.
Root Cause
SessionDelegatedoes not implementurlSession(_:didReceive challenge:completionHandler:). While the expected behavior is thatURLSessionfalls back to default system trust evaluation, in practice this can cause the connection to be silently rejected when a custom delegate is set without handling authentication challenges.Steps to Reproduce
Expected Behavior
The SSE connection should succeed through the proxy since the CA certificate is installed and trusted at the OS level.
URLSessionshould use the system's default trust evaluation which respects user-installed CA certificates.Suggested Fix
Add explicit
.performDefaultHandlingtoSessionDelegate:This explicitly delegates to the system's default trust evaluation, which correctly handles user-installed CA certificates. This has no effect on normal (non-proxy) connections.
Environment