GHSA-8J62-F337-86XW
SSRF via base_url in llm.agent/ai.model: base-install aiohttp fallback lacks connect-time guard (DNS rebinding to metadata)
CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:L/A:N
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-8J62-F337-86XW divulgada · CVSS 7.1 (GitHub) | |
| Remediación | Parche 2.33.0 | flyto-core · 0 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
The `llm.agent` and `ai.model` modules let an authenticated recipe author supply a custom OpenAI-compatible `base_url`. Before the model is built, the URL is validated once by `validate_url_with_env_config`, but that check resolves the host a single time and returns the hostname unchanged; it does not pin the approved address. During execution the request is issued by `_http_post` in `src/core/modules/atomic/llm/_chat_models.py`. On a base install (where the optional `httpx` dependency is absent), `_http_post` falls into its `except ImportError` branch and opens a bare `aiohttp.ClientSession()` with no connect-time SSRF guard. aiohttp then performs a second, independent DNS lookup at connect time, so an attacker who controls DNS (short TTL, answering a public address for the validation lookup and a private or link-local address for the connection) reaches internal hosts and the cloud instance metadata endpoint. The caller-supplied Authorization header is delivered to that internal target and the response body is returned into the agent output, yielding a semi-blind SSRF read and theft of cloud IAM credentials.
Root Cause
The project enforces its outbound SSRF policy at connect time through `_SSRFGuardedResolver`, which is installed only by the `guarded_client_session`, `guarded_httpx_client`, and `ssrf_guarded_connector` helpers in `src/core/utils.py`. The build-time `validate_url_with_env_config` performs a one-shot resolve-and-check and returns the hostname, so on its own it cannot defend against a host that resolves to a different address at connect time (the DNS-rebinding TOCTOU that the connect-time resolver was introduced to close). The commit that unified the outbound policy across HTTP clients migrated only the `try: import httpx` branch of `_http_post` to `guarded_httpx_client` and left the sibling `except ImportError` aiohttp branch as a bare `aiohttp.ClientSession()`. That fallback branch is the one a base install runs, and it never passes through any connect-time guard, so the sole remaining protection is the build-time check that DNS rebinding defeats.
Affected function: _http_post (except ImportError / aiohttp fallback)
Location: src/core/modules/atomic/llm/_chat_models.py:108-116 (sink at line 111: async with aiohttp.ClientSession() as session)
Reached via: OpenAIChatModel.chat (src/core/modules/atomic/llm/_chat_models.py:172) with caller-controlled base_url
Missing guard: connect-time _SSRFGuardedResolver (src/core/utils.py:942-997), applied by guarded_client_session but omitted hereImpact
An authenticated recipe or workflow author (a lower-trust role than the runner operator, and the same role the existing base_url SSRF advisories defend against) can cause the runner to issue requests to arbitrary internal hosts and to the cloud metadata service at 169.254.169.254. The internal or metadata response body is returned into the agent output (semi-blind SSRF read), and the caller-controlled Authorization Bearer header is delivered to the internal target. Reading the metadata endpoint yields cloud IAM credentials scoped to the runner's role, so the demonstrated capability includes cloud credential exfiltration and internal service reconnaissance. Exploitation requires the deployment to be a base install without the optional `httpx` dependency and requires the attacker to control DNS for the supplied host; these are the preconditions, not a limitation on impact once met.
Proof of Concept
Setup: base install condition forced by making httpx unavailable (sys.modules["httpx"] = None),
exactly the import posture of a deployment without the optional httpx dependency.
A mock internal service is bound on a private RFC1918 address; a hostname resolving to that
private address is used as a hermetic, deterministic stand-in for a TTL-0 rebinding host.
The connect-time code path exercised is identical to a live rebind.Reproduction steps:
1. Force the base-install branch by making `import httpx` fail so `_http_post` takes the aiohttp fallback.
2. Bind a mock service on an internal RFC1918 address and point a hostname at it.
3. Drive `_http_post` (as `OpenAIChatModel.chat` does) with that hostname as `base_url` and a dummy Authorization Bearer header.
4. Repeat the identical connect through `guarded_client_session()` as a negative control.
# Drives _http_post through the aiohttp fallback against an internal address,
# then repeats the identical connect through guarded_client_session() as a control.
sys.modules["httpx"] = None # base-install condition
url = f"http://{internal_hostname}/chat/completions"
headers = {"Authorization": "Bearer sk-dummy"}
await _http_post(url, headers, {"model": "x", "messages": []}) # reaches internal target
async with guarded_client_session() as s: # control: blocked
await s.post(url, headers=headers, json={})[i] using hostname ip-10-0-0-203 resolving to private 10.0.0.203 (DNS-rebinding stand-in)
[A] _http_post (aiohttp fallback) reached internal ip-10-0-0-203 (10.0.0.203): True; Bearer credential delivered to it: True
[B] guarded_client_session() refused the same connect: SSRFError: Blocked connect-time resolution (DNS-rebinding guard): ip-10-0-0-203 -> 10.0.0.203.
RESULT: DEFECT CONFIRMED
EXIT=0Attack Chain
- Exposure: An authenticated recipe author submits a workflow to the Execution API containing an `llm.agent` node (or an `ai.model` sub-node). The `llm` and `ai` module categories register unconditionally on a base install; neither imports `httpx` or `openai` at module scope, so both are present without the optional extras.
- Control: The attacker fully controls `provider` (any value other than `anthropic` routes to the OpenAI-compatible model), `api_key` (a caller-supplied dummy), and `base_url` (an attacker-authoritative DNS name with a short TTL).
- Path: `_resolve_chat_model` calls `_guard_inline_base_url(base_url)` once, then `create_chat_model(base_url=...)` builds `OpenAIChatModel`, which stores `base_url` verbatim. At run time `chat()` builds `f"{self._base_url}/chat/completions"` with the Bearer header and calls `_http_post`. The `ai.model` path is symmetric.
- Guard: The build-time `validate_url_with_env_config` resolves the host once and returns the hostname (no IP pinning); `assert_env_credential_endpoint_allowed` no-ops because the caller supplied its own key (`if not key_from_env: return`); and the connect-time `_SSRFGuardedResolver` is absent from the bare `aiohttp.ClientSession()` in the fallback. All three fail to block the path.
- Primitive: aiohttp performs a second DNS lookup at connect time; the rebinding host now answers a private or link-local address, and the socket connects there with no revalidation.
- Result: Semi-blind SSRF read of internal services and the cloud metadata endpoint (169.254.169.254), returning IAM credentials into the agent output and delivering the caller Authorization header to the internal target. This crosses from the runner's authority into the metadata service and internal network (scope change).
Bypass Evidence
This is an incomplete fix. The canonical prior remediation is the connect-time DNS-rebinding guard published as GHSA-pfg2-w999-497v (CVE-2026-77313) and GHSA-6pm8-6f34-9v3g (CVE-2026-77316), together with the guard-unification change that migrated HTTP call sites to the shared helpers. Those guards exist on the current release, but the `except ImportError` aiohttp branch of `_http_post` was never routed through them. `git show` on the guard-unification commit confirms its only hunk in this file changed `httpx.AsyncClient(timeout=120)` to `guarded_httpx_client(timeout=120)` and left the aiohttp fallback bare; per-tag inspection of v2.28.0, v2.29.0, v2.31.0, v2.31.2, and HEAD shows the fallback bare in every release.
Disproof attempts, each of which failed to refute the finding: (1) checked whether `httpx` is a base dependency, it is only in the optional `ai`/`all` extras while base dependencies carry `aiohttp`, so a base install takes the fallback; (2) checked whether the build-time validation pins the approved IP, it returns the URL unchanged so connect time is a second independent lookup; (3) checked for a global aiohttp resolver monkeypatch, none exists, the guard is per call site; (4) checked whether the modules fail to load on a base install, both categories register unconditionally with no module-scope `httpx`/`openai` import; (5) checked whether only the hardcoded-URL Anthropic caller reaches `_http_post`, the OpenAI-compatible caller uses the attacker `base_url` and every non-anthropic provider routes to it; (6) checked whether `chat()` re-validates at connect time, it reuses the stored `base_url` and never re-checks; (7) checked whether a host resolving directly to a private address would already be caught, it is caught by the build-time check, which is why reaching internal targets genuinely requires DNS rebinding (justifying the high attack complexity). A workspace proof of concept executed with exit 0, showing the fallback reaches an internal RFC1918 target and delivers the Bearer header while `guarded_client_session()` blocks the identical connect.
Affected Versions
- `Ecosystem: PyPI`
- `Package: flyto-core`
- `Confirmed affected range: >= 2.28.0, <= 2.31.2`
- `Latest release checked: 2.31.2 (PyPI); repository HEAD (git describe v2.31.2-7-ge5e4c0a) also affected`
- `Fix status: not fixed (no released version removes the bare aiohttp fallback)`
Per-tag inspection of the affected file confirms the bare aiohttp fallback and the caller-controlled `base_url` reachability through it are present in every tagged release from v2.28.0 through v2.31.2 and at HEAD. The connect-time guard family has existed since v2.28.0, but this sink's aiohttp branch was never migrated to it. The guard-unification commit shipped in v2.31.0 is where the fix became present but incomplete (httpx branch guarded, aiohttp branch left bare); it did not introduce the base-install exposure, which predates it. The lower boundary below v2.28.0 is unverified because only v2.28.0 and later tags were available for inspection. The `pyproject` version field reads 2.32.0, but no such release or tag exists, so it is treated as unreleased HEAD.
Suggested Fix
Enforce the connect-time outbound SSRF policy on both branches of `_http_post`. Route the `except ImportError` aiohttp fallback through `guarded_client_session()` so the address the guard validated is the address the socket connects to, matching the httpx branch and the sibling `chat.py` call sites that already guard both clients. More generally, ensure no outbound request is issued through a bare `aiohttp.ClientSession()` or `httpx.AsyncClient()`; a construction-site test or lint that rejects unguarded client construction outside `core/utils.py` should be extended to cover this fallback. As an interim mitigation without a code change, installing the `ai` (or `all`) extra so `httpx` is present forces the guarded httpx branch for this sink; operators can also restrict outbound egress from the runner to known destinations. Maintainers should additionally audit `src/core/modules/atomic/llm/_providers.py` for the same bare-fallback pattern.
Reported by zx (GitHub: @manus-pi).
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
pypiflyto-core |
Corregida | 2.33.0 | 0 d | 2.41.0 no afectada |
2.33.0Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/flytohub/flyto-core/security/advisories/GHSA-8j62-f337-86xwLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
