Skip to content

SSE connections fail silently through MITM proxies (missing auth challenge delegate) #50

@liefran-sim

Description

@liefran-sim

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

  1. Install and trust a proxy CA certificate on an iOS device (e.g., mitmproxy CA)
  2. Configure the device to use the proxy
  3. Open an SSE connection using EventSource to an HTTPS endpoint
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions