Skip to content

Fix InsecureConnectionBuilder (Android) and add allowInsecureConnections support (iOS/macOS)#650

Open
jrevillard wants to merge 1 commit into
MaikuB:masterfrom
jrevillard:fix/insecure-connection-builder
Open

Fix InsecureConnectionBuilder (Android) and add allowInsecureConnections support (iOS/macOS)#650
jrevillard wants to merge 1 commit into
MaikuB:masterfrom
jrevillard:fix/insecure-connection-builder

Conversation

@jrevillard
Copy link
Copy Markdown

Summary

Fixes #386

The allowInsecureConnections parameter does not work on any platform:

  • Android: InsecureConnectionBuilder.openConnection() is a no-op — it calls URL.openConnection() without any SSL/TLS configuration, so HTTPS connections still validate the certificate chain normally.
  • iOS/macOS: The allowInsecureConnections parameter is completely ignored. There is no equivalent of InsecureConnectionBuilder, and no SSL bypass mechanism exists.

This makes it impossible to use the plugin against OIDC providers with self-signed certificates during development (e.g., local Keycloak instances).

Changes

Android

Replaced the no-op InsecureConnectionBuilder.openConnection() with a real implementation that:

  • Creates an SSLContext with a trust-all X509TrustManager
  • Sets a permissive HostnameVerifier on HttpsURLConnection
  • Only applies when allowInsecureConnections=true (the existing routing in FlutterAppauthPlugin via getConnectionBuilder() is unchanged)

iOS & macOS

Added InsecureURLProtocol (an NSURLProtocol subclass) that:

  • Intercepts HTTPS requests when registered
  • Creates a private NSURLSession with empty protocolClasses to avoid recursion
  • Trusts all server certificates via NSURLSessionAuthChallengeUseCredential
  • Is registered before and unregistered after each plugin method call, only when allowInsecureConnections=true

Also added allowInsecureConnections property to TokenRequestParameters and EndSessionRequestParameters on iOS/macOS (was previously only defined on Android).

Testing

Verified on Android emulator against a local Keycloak instance with a self-signed certificate:

  • Endpoint discovery
  • Authorization + token exchange
  • Token refresh
  • End session (logout)

All operations succeed without "Network error" when allowInsecureConnections=true.

Security Note

The SSL bypass is only active when allowInsecureConnections=true is explicitly passed by the caller. Production configurations use CA-signed certificates and allowInsecureConnections=false (the default), so this change has no production impact.

…ecureConnections support for iOS/macOS

Android: Replace no-op InsecureConnectionBuilder.openConnection() with real SSL
bypass using TrustManager + HostnameVerifier when allowInsecureConnections=true.

iOS/macOS: Add InsecureURLProtocol (NSURLProtocol subclass) that intercepts HTTPS
connections and trusts all certificates. Register/unregister conditionally based on
allowInsecureConnections flag. Previously, the flag was completely ignored on Apple
platforms.

Fixes MaikuB#386
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment