Skip to content

Android: pinned OkHttpClient lazy fallback can permanently bind to non-pinned client #7248

Done

Description

@diegolmello

Problem

MediaCallsAnswerRequest.kt:45-53 and DDPClient.kt:29 both initialize the OkHttp client via a companion by lazy block:

```kotlin
private val httpClient: OkHttpClient by lazy {
SSLPinningTurboModule.getSharedOkHttpClient() ?: OkHttpClient()
}
```

If a VoIP notification (or DDP message) arrives during cold start before the user has selected a certificate, the lazy initializer triggers when the shared pinned client is still null, permanently binding to a plain OkHttpClient() for the process lifetime. Subsequent calls — including manual certificate selection later in the session — reuse the cached non-pinned fallback and silently bypass SSL pinning.

Where this surfaces

  • VoIP accept REST (MediaCallsAnswerRequest.fetch) when invoked from a PushKit/FCM cold-start handler
  • DDPClient connections under similar cold-start conditions

Suggested fix

Resolve the shared client at each call site rather than at lazy initialization, OR fail-fast with onResult(false) when getSharedOkHttpClient() returns null.

Background

Spotted by CodeRabbit on #7245 — this is a pre-existing bug, not introduced by that PR. Filing separately so it doesn't block the release-readiness queue.

Activity

  1. deepak0x commented on Apr 28, 2026

    @deepak0x
    Contributor

    I looked at both MediaCallsAnswerRequest.kt and DDPClient.kt in feat.voip-lib-new.

    The root cause is that the by lazy initializer runs once at first use. If a VoIP notification arrives before SSLPinningTurboModule has a shared client ready, the fallback plain OkHttpClient() gets cached permanently for the process lifetime.

    Two approaches:

    Option A — resolve at call site: Drop the by lazy and call SSLPinningTurboModule.getSharedOkHttpClient() inside execute() / connect() each time. Build the client with the required timeouts on every call. No permanent caching.

    Option B — fail-fast: Keep the lazy pattern but replace ?: OkHttpClient() with an explicit null check — if the shared client is not ready, immediately invoke onResult(false) / the connect callback with false and return. No silent downgrade to an unpinned client.

    Option B is simpler and arguably safer since it makes the failure explicit rather than silently proceeding without pinning. Option A works too but rebuilds the client on every call.

    What are your views on it? Happy to submit a PR for whichever approach you prefer.

  2. diegolmello commented on Nov 26, 2026

    @diegolmello
    MemberAuthor

    Fixed by fix: send client certificate through expo/fetch on iOS and Android (4.78.0): the shared OkHttp client factory with client-certificate support is installed when the app process starts, before any VoIP push or DDP connection, and the fallback to a plain OkHttpClient is gone. Certificates picked later apply to existing clients too. Closing.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions