{"id":"CVE-2026-26013","aliases":["CVE-2026-26013","GHSA-2g6r-c272-w58r","PYSEC-2026-2562"],"related":[],"kind":"vulnerability","state":"published","title":"LangChain affected by SSRF via image_url token counting in ChatOpenAI.get_num_tokens_from_messages","summary":"LangChain is a framework for building agents and LLM-powered applications. Prior to 1.2.11, the ChatOpenAI.get_num_tokens_from_messages() method fetches arbitrary image_url values without validation when computing token counts for vision-enabled models. This allows attackers to trigger Server-Side Request Forgery (SSRF) attacks by providing malicious image URLs in user input. This vulnerability is fixed in 1.2.11.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"LangChain is a framework for building agents and LLM-powered applications. Prior to 1.2.11, the ChatOpenAI.get_num_tokens_from_messages() method fetches arbitrary image_url values without validation when computing token counts for vision-enabled models. This allows attackers to trigger Server-Side Request Forgery (SSRF) attacks by providing malicious image URLs in user input. This vulnerability is fixed in 1.2.11.","source":"cvelist"},{"lang":"en","text":"## Server-Side Request Forgery (SSRF) in ChatOpenAI Image Token Counting\n\n### Summary\nThe `ChatOpenAI.get_num_tokens_from_messages()` method fetches arbitrary `image_url` values without validation when computing token counts for vision-enabled models. This allows attackers to trigger Server-Side Request Forgery (SSRF) attacks by providing malicious image URLs in user input.\n\n### Severity\n**Low** - The vulnerability allows SSRF attacks but has limited impact due to:\n- Responses are not returned to the attacker (blind SSRF)\n- Default 5-second timeout limits resource exhaustion\n- Non-image responses fail at PIL image parsing\n\n### Impact\nAn attacker who can control image URLs passed to `get_num_tokens_from_messages()` can:\n- Trigger HTTP requests from the application server to arbitrary internal or external URLs\n- Cause the server to access internal network resources (private IPs, cloud metadata endpoints)\n- Cause minor resource consumption through image downloads (bounded by timeout)\n\n**Note:** This vulnerability occurs during token counting, which may happen outside of model invocation (e.g., in logging, metrics, or token budgeting flows).\n\n### Details\nThe vulnerable code path:\n1. `get_num_tokens_from_messages()` processes messages containing `image_url` content blocks\n2. For images without `detail: \"low\"`, it calls `_url_to_size()` to fetch the image and compute token counts\n3. `_url_to_size()` performs `httpx.get(image_source)` on any URL without validation\n4. Prior to the patch, there was no SSRF protection, size limits, or explicit timeout\n\n**File:** `libs/partners/openai/langchain_openai/chat_models/base.py`\n\n### Patches\nThe vulnerability has been patched in `langchain-openai==1.1.9` (requires `langchain-core==1.2.11`).\n\nThe patch adds:\n1. **SSRF validation** using `langchain_core._security._ssrf_protection.validate_safe_url()` to block:\n   - Private IP ranges (RFC 1918, loopback, link-local)\n   - Cloud metadata endpoints (169.254.169.254, etc.)\n   - Invalid URL schemes\n2. **Explicit size limits** (50 MB maximum, matching OpenAI's payload limit)\n3. **Explicit timeout** (5 seconds, same as `httpx.get` default)\n4. **Allow disabling image fetching** via `allow_fetching_images=False` parameter\n\n### Workarounds\nIf you cannot upgrade immediately:\n\n1. **Sanitize input:** Validate and filter `image_url` values before passing messages to token counting or model invocation\n2. **Use network controls:** Implement egress filtering to prevent outbound requests to private IPs","format":"markdown","source":"ghsa"},{"lang":"es","text":"LangChain es un framework para construir agentes y aplicaciones impulsadas por LLM. Antes de la versión 1.2.11, el método ChatOpenAI.get_num_tokens_from_messages() obtiene valores arbitrarios de image_url sin validación al calcular el recuento de tokens para modelos habilitados para visión. Esto permite a los atacantes desencadenar ataques de falsificación de petición del lado del servidor (SSRF) al proporcionar URLs de imagen maliciosas en la entrada del usuario. Esta vulnerabilidad está corregida en la versión 1.2.11.","source":"nvd"}],"published":"2026-02-10T21:51:07.741Z","modified":"2026-09-10T03:50:33.793Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L","score":3.7,"rating":"LOW"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L","score":3.7,"rating":"LOW"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L","score":3.7,"rating":"LOW"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L","score":3.7,"rating":"LOW"}],"cwes":["CWE-918"],"affected":[{"ranges":[{"version":"< 1.2.11","status":"affected"}],"vendor":"langchain-ai","product":"langchain","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"1.2.11"}],"ecosystem":"PyPI","package":"langchain-core","purl":"pkg:pypi/langchain-core","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"1.2.11"}],"vendor":"langchain","product":"langchain_core","cpe":"cpe:2.3:a:langchain:langchain_core:*:*:*:*:*:python:*:*","source":"nvd"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"1.2.11"}],"ecosystem":"PyPI","package":"langchain-core","purl":"pkg:pypi/langchain-core","source":"pysec"}],"references":[{"url":"https://github.com/langchain-ai/langchain/security/advisories/GHSA-2g6r-c272-w58r","tags":["mitigation","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/langchain-ai/langchain/commit/2b4b1dc29a833d4053deba4c2b77a3848c834565","tags":["patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/langchain-ai/langchain/releases/tag/langchain-core%3D%3D1.2.11","tags":["product","release-notes","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-26013","tags":["advisory"],"sources":["ghsa","pysec"]},{"url":"https://github.com/langchain-ai/langchain","tags":["package"],"sources":["ghsa","pysec"]},{"url":"https://pypi.org/project/langchain-core","tags":["package"],"sources":["pysec"]},{"url":"https://github.com/advisories/GHSA-2g6r-c272-w58r","tags":["advisory"],"sources":["pysec"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"none","automatable":"no","technicalImpact":"partial","date":"2026-02-11T21:26:20.888Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-26013","url":"https://www.cve.org/CVERecord?id=CVE-2026-26013","licence":"CVE Terms of Use","modified":"2026-02-11T21:26:34.029Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-2g6r-c272-w58r","url":"https://github.com/advisories/GHSA-2g6r-c272-w58r","licence":"CC-BY-4.0","modified":"2026-09-10T03:50:33.793Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-26013","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-26013","licence":"Public domain","modified":"2026-06-17T10:25:35.927Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-2562","url":"https://osv.dev/vulnerability/PYSEC-2026-2562","licence":"CC-BY-4.0","modified":"2026-07-13T16:31:48.686Z"}],"updatedAt":"2026-11-25T22:59:13.758Z","epss":{"score":0.00424,"percentile":0.38621,"date":"2026-12-01T12:00:22.000Z"}}