# Code maintenance AA-145 - Route LLM inference traffic through the SSRF-filtered httpx client

Project: Stream Agents & Assistants
Status: closed
URL: https://community.openproject.org/work_packages/AA-145

## OPEN POINTS

_No work packages_

## Subtasks

_No work packages_

## Details

| Attribute | Value |
| --- | --- |
| Assignee | OP Dev AI team |
| Accountable |  |
| Designer |  |
| Developers | Andreas Eiselt |
| Requires doc change | No |
| Date |  |
| Priority | Medium |
| Target versions | 18.0.0 |
| Module | Artificial Intelligence (AI) |
| List |  |
| Labels |  |

## Estimates and progress

| Attribute | Value |
| --- | --- |
| Work |  |
| Remaining work |  |

## Description

Chat and embedding requests to an LLM connection's `base_url` skip the SSRF filter that protects OpenProject's other outbound HTTP. Tom Hykel and Kabiru Mwenja raised this in the review of <mention class="mention" data-id="24879" data-type="work_package" data-text="#24879">#24879</mention> ([thread 1](https://github.com/opf/openproject/pull/24879#discussion_r3990161684), [thread 2](https://github.com/opf/openproject/pull/24879#discussion_r4038478196)), and it was deferred out of AI-3. Since <mention class="mention" data-id="24880" data-type="work_package" data-text="#24880">#24880</mention>, `LlmServerValidator` checks the host for every API format when an administrator saves, and requires every resolved address to be allowed. Connections provisioned from the environment skip that check, and nothing checks again when a request is sent, so a DNS change after saving is not caught.

E.g. currently `Llm::Session` hands requests to RubyLLM, which opens its own Faraday connection over `net_http`. Only model discovery on `Llm::Client` uses `OpenProject.httpx`:

``` ruby
.plugin(:ssrf_filter, safe_private_ranges: OpenProject::Configuration.ssrf_protection_ip_allowlist)
```

Instead `Session#context` could set `config.faraday_adapter` to a subclass of `Faraday::Adapter::HTTPX` with that plugin and `HttpxSsrfCustomErrorMessage`, and `Llm::Errors.from_transport` could map a blocked address to `Llm::Errors::SsrfError`.

  - Spike first: error shape, streaming, `request_timeout`.
  - Then decide whether discovery moves onto RubyLLM so `Llm::Client` can go. Discovery needs the raw `/models` body (`max_model_len`, `root`) and must keep OpenRouter's second `/models?output_modalities=embeddings` request, bare-array normalisation and JSON parsing whatever the content type.

### Acceptance criteria

  - Inference to a blocked address raises `Llm::Errors::SsrfError`; the allowlist still applies.
  - Streaming, timeouts and `custom_headers` (still overriding `Authorization`) work as before.
