CVE-2026-41488
JSON

3.1low

angchain-openai: Image token counting SSRF protection can be bypassed via DNS rebinding

Severity
3.1low CVSS:3.1 by GitHub_M
Exploit likelihood
0.16% (higher than 5% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-r7w7-9xr2-qq2rPYSEC-2026-76

Description

LangChain is a framework for building agents and LLM-powered applications. Prior to 1.1.14, langchain-openai's _url_to_size() helper (used by get_num_tokens_from_messages for image token counting) validated URLs for SSRF protection and then fetched them in a separate network operation with independent DNS resolution. This left a TOCTOU / DNS rebinding window: an attacker-controlled hostname could resolve to a public IP during validation and then to a private/localhost IP during the actual fetch.

Affected

Product or packageVersionsReported by
langchain-ai langchain-openai< 1.1.14CVE List
langchain-openai (PyPI)before 1.1.14GitHub Advisory Database, PyPA Advisory Database
langchain langchain-openaibefore 1.1.14NVD

All scores

GitHub_M3.1low CVSS:3.1CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:N/A:N
GitHub3.1low CVSS:3.1CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:N/A:N
PyPA Advisory Database3.1low CVSS:3.1CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:N/A:N

Classification

CWE-918

SSVC (CISA-ADP): exploitation none, automatable no, technical impact partial.

What each source says

CVE List

LangChain is a framework for building agents and LLM-powered applications. Prior to 1.1.14, langchain-openai's _url_to_size() helper (used by get_num_tokens_from_messages for image token counting) validated URLs for SSRF protection and then fetched them in a separate network operation with independent DNS resolution. This left a TOCTOU / DNS rebinding window: an attacker-controlled hostname could resolve to a public IP during validation and then to a private/localhost IP during the actual fetch.

GitHub Advisory Database

Summary

langchain-openai's _url_to_size() helper (used by get_num_tokens_from_messages for image token counting) validated URLs for SSRF protection and then fetched them in a separate network operation with independent DNS resolution. This left a TOCTOU / DNS rebinding window: an attacker-controlled hostname could resolve to a public IP during validation and then to a private/localhost IP during the actual fetch.

The practical impact is limited because the fetched response body is passed directly to Pillow's Image.open() to extract dimensions — the response content is never returned, logged, or otherwise exposed to the caller. An attacker cannot exfiltrate data from internal services through this path. A potential risk is blind probing (inferring whether an internal host/port is open based on timing or error behavior).

Affected versions

  • langchain-openai < 1.1.14

Patched versions

  • langchain-openai >= 1.1.14 (requires langchain-core >= 1.2.31)

Affected code

File: libs/partners/openai/langchain_openai/chat_models/base.py — _url_to_size()

The vulnerable pattern was a validate-then-fetch with separate DNS resolution:

validate_safe_url(image_source, allow_private=False, allow_http=True)
# ... separate network operation with independent DNS resolution ...
response = httpx.get(image_source, timeout=timeout)

Fix

The fix replaces the validate-then-fetch pattern with an SSRF-safe httpx transport (SSRFSafeSyncTransport from langchain-core) that:

  • Resolves DNS once and validates all returned IPs against a policy (private ranges, cloud metadata, localhost, k8s internal DNS)
  • Pins the connection to the validated IP, eliminating the DNS rebinding window
  • Disables redirect following to prevent redirect-based SSRF bypasses

This fix was released in langchain-openai 1.1.14.

NVD (es)

LangChain es un framework para construir agentes y aplicaciones impulsadas por LLM. Antes de la versión 1.1.14, el asistente _url_to_size() de langchain-openai (utilizado por get_num_tokens_from_messages para el recuento de tokens de imagen) validaba las URL para la protección contra SSRF y luego las obtenía en una operación de red separada con resolución DNS independiente. Esto dejaba una ventana de TOCTOU / revinculación de DNS: un nombre de host controlado por un atacante podría resolverse a una IP pública durante la validación y luego a una IP privada/localhost durante la obtención real.

References

Sources

SourceRecordLicence
CVE ListCVE-2026-41488 changed 2026-04-27CVE Terms of Use
GitHub Advisory DatabaseGHSA-r7w7-9xr2-qq2r changed 2026-06-06CC-BY-4.0
NVDCVE-2026-41488 changed 2026-10-26Public domain
PyPA Advisory DatabasePYSEC-2026-76 changed 2026-05-20CC-BY-4.0