Am I affected?

type your req_llm version to check

Description

Improper Certificate Validation vulnerability in the WebSocket streaming client in agentjido req_llm allows an on-path attacker to read and modify OpenAI WebSocket sessions, including the authorization bearer token, via a TLS certificate the client does not trust. ReqLLM.Streaming.WebSocketSession.Client.start/3 in lib/req_llm/streaming/web_socket_session/client.ex starts WebSockex without TLS options, and WebSockex defaults to insecure: true, which connects with verify: :verify_none. The option allowlist also drops any caller-supplied cacerts or ssl_options, so an application cannot turn verification on.

The OpenAI Responses, Realtime, and Codex WebSocket paths reach this client and send the API key or OAuth access token in the authorization header. HTTP streaming through Finch and the HTTP/2 duplex session through Mint verify certificates and are not affected.

This issue affects req_llm: from 1.9.0 before 1.29.0.

Technical analysis

1. Entry points. ReqLLM.Providers.OpenAI.WebSocket.responses_url/2 and realtime_url/2, and the Codex provider's codex_websocket_url/1, turn the provider base URL into a wss:// URL and start ReqLLM.Streaming.WebSocketSession with an authorization header that carries the OpenAI API key or the OAuth access token.

2. Missing TLS options. WebSocketSession.init/1 passes only the headers and the timeouts to WebSocketSession.Client.start/3, and the allowlist in start/3 forwards only name, debug, async, handle_initial_conn_failure, and the socket timeouts to WebSockex.start/4. No insecure, cacerts, or ssl_options value reaches WebSockex, and a caller cannot inject one.

3. Insecure default. WebSockex 0.5.1 sets insecure: true when the option is absent and opens the wss:// connection through :ssl.connect/4 with verify: :verify_none. Any certificate completes the handshake, so an attacker who terminates TLS on the path receives the upgrade request with the bearer token and every frame of the session, and can rewrite frames in either direction.

Proof of concept

  1. Start a TLS endpoint on localhost with a self-signed certificate chain that no trust store contains, and let it answer the WebSocket upgrade with 101 Switching Protocols.
  2. On a vulnerable version, call ReqLLM.Streaming.WebSocketSession.start_link/2 with wss://localhost:<port>/socket and headers: [{"authorization", "Bearer <token>"}], then await_connected/2.
  3. await_connected/2 returns :ok, the endpoint completes the TLS handshake, and the endpoint receives the upgrade request carrying the bearer token. On 1.29.0 the same call returns {:error, %WebSockex.ConnError{original: {:tls_alert, {:unknown_ca, _}}}} and the endpoint never sees the request.

Weaknesses & attack patterns

Weakness

CWE-295 · Improper Certificate Validation in catalog → MITRE ↗

Attack patterns

CAPEC-94 · Adversary in the Middle (AiTM) MITRE ↗

An attacker on the network path between an application and the OpenAI endpoint presents their own certificate, obtains the OpenAI API key or OAuth access token and the full session content, and can alter model output and tool calls before the application acts on them. Every application that uses the OpenAI Responses, Realtime, or Codex WebSocket paths is affected.

Affected — Hex / req_llm Hex.pm ↗ Repository ↗

≥ 1.9.0 < 1.29.0 affected
every other version: unaffected
cpe cpe:2.3:a:agentjido:req_llm:*:*:*:*:*:*:*:*
version type semver
modules · source files · routines
modules 'Elixir.ReqLLM.Streaming.WebSocketSession.Client' · 'Elixir.ReqLLM.Streaming.WebSocketSession' · 'Elixir.ReqLLM.Providers.OpenAI.WebSocket' · 'Elixir.ReqLLM.OpenAI.Realtime' · 'Elixir.ReqLLM.Providers.OpenAICodex'
source files lib/req_llm/streaming/web_socket_session/client.ex · lib/req_llm/streaming/web_socket_session.ex · lib/req_llm/providers/openai/web_socket.ex · lib/req_llm/openai/realtime.ex · lib/req_llm/providers/openai_codex.ex
routines 'Elixir.ReqLLM.Streaming.WebSocketSession.Client':start/3 · 'Elixir.ReqLLM.Streaming.WebSocketSession':start_link/2 · 'Elixir.ReqLLM.Streaming.WebSocketSession':init/1 · 'Elixir.ReqLLM.Providers.OpenAI.WebSocket':start_responses_session/2 · 'Elixir.ReqLLM.OpenAI.Realtime':connect/2 · 'Elixir.ReqLLM.Providers.OpenAICodex':start_responses_session/2

Affected — GitHub / agentjido/req_llm Repository ↗

≥ a389d71 < c7264fc affected
every other version: unaffected
cpe cpe:2.3:a:agentjido:req_llm:*:*:*:*:*:*:*:*
version type git
modules · source files · routines
modules 'Elixir.ReqLLM.Streaming.WebSocketSession.Client' · 'Elixir.ReqLLM.Streaming.WebSocketSession' · 'Elixir.ReqLLM.Providers.OpenAI.WebSocket' · 'Elixir.ReqLLM.OpenAI.Realtime' · 'Elixir.ReqLLM.Providers.OpenAICodex'
source files lib/req_llm/streaming/web_socket_session/client.ex · lib/req_llm/streaming/web_socket_session.ex · lib/req_llm/providers/openai/web_socket.ex · lib/req_llm/openai/realtime.ex · lib/req_llm/providers/openai_codex.ex
routines 'Elixir.ReqLLM.Streaming.WebSocketSession.Client':start/3 · 'Elixir.ReqLLM.Streaming.WebSocketSession':start_link/2 · 'Elixir.ReqLLM.Streaming.WebSocketSession':init/1 · 'Elixir.ReqLLM.Providers.OpenAI.WebSocket':start_responses_session/2 · 'Elixir.ReqLLM.OpenAI.Realtime':connect/2 · 'Elixir.ReqLLM.Providers.OpenAICodex':start_responses_session/2

Workarounds

Leave the openai_stream_transport provider option at its default :sse for the OpenAI and OpenAI Codex providers, and do not call ReqLLM.Providers.OpenAI.WebSocket.start_responses_session/2 directly. Responses streaming then runs over HTTP through Finch, which verifies certificates. ReqLLM.OpenAI.Realtime.connect/2 has no HTTP alternative, so do not use it on an affected version.

References

Credits

Neil Berkman Reporter Finder
Mike Hostetler Remediation developer
Jonatan Männchen / EEF Coordinator

CVSS breakdown

CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:H/VA:N/SC:N/SI:N/SA:N
« All CVEs