Skip to content
BJypv Ai Mg

BJypv Ai Mg

hackmd.io • October 15, 2026

# Unauthenticated SSRF to Loopback/Docker-Host via Default-Trusted `x-portkey-custom-host` (Portkey AI Gateway)

![status](

![CVSS](

![CWE](

![component](

**Reported by:** hieuPenguinnn ([github.com/hieuPenguinnn](

**Project:** [Portkey-AI/gateway]( AI gateway / LLM proxy

**Affected:** `@portkey-ai/gateway` 1.15.2, verified at commit `669825cbe89ee51569918b8f78a9db486fd69dd4` (2026-05-25; source review 2026-10-13)

The gateway accepts a user-controlled `x-portkey-custom-host` header and uses it verbatim as the outbound base URL for provider requests. When `TRUSTED_CUSTOM_HOSTS` is unset (the default), the validator short-circuits and trusts `localhost`, `127.0.0.1`, `::1`, `host.docker.internal`, and any `*.localhost` host - returning `true` *before* its private-IP/metadata blocks run. The `/v1/*` routes require no admin authentication, and the Ollama provider needs no API key, so an unauthenticated caller can make the gateway issue requests to loopback and Docker-host services and relay their responses back.

### 1. `/v1/*` routes have no admin-auth layer

app.post('/v1/chat/completions', requestValidator, chatCompletionsHandler);

app.post('/v1/completions', requestValidator, completionsHandler);

app.post('/v1/*', requestValidator, proxyHandler);

app.get('/v1/:path{(?!realtime).*}', requestValidator, proxyHandler);

Source: `src/index.ts` (route block around `#L135-L295`). The only `app.use('*', ...)` middlewares are non-auth (pretty-JSON, logging, hooks, cache); no admin token / session gate precedes `/v1/*`.

### 2. The validator trusts loopback/docker-host by default

const TRUSTED_CUSTOM_HOSTS = (c?: Context) => {

const envVar = Environment(c)?.TRUSTED_CUSTOM_HOSTS;

if (/* unset */) return new Set(['localhost', '127.0.0.1', '::1', 'host.docker.internal']);

Source: `src/middlewares/requestValidator/index.ts#L55-L66`

(trustedHosts.has('localhost') && host.endsWith('.localhost'));

if (url.port && !isValidPort(url.port)) return false;

return true; // { return providerOptions.customHost ?? ''; },

Source: `src/providers/ollama/api.ts#L3-L9`; the config schema allows the Ollama provider without an API key (`src/middlewares/requestValidator/schema/config.ts#L128-L152`). So the request is genuinely unauthenticated.

participant A as Unauthenticated attacker

participant I as Loopback/docker-host service

A->>G: POST /v1/chat/completions (x-portkey-provider: ollama, x-portkey-custom-host:

Note over G: isTrustedHost(127.0.0.1) -> return true (no key needed)

G->>I: POST

G-->>A: relayed response / connection error

No API key or admin token is sent. Use a self-owned gateway; replace `TARGET`/`PORT` with a benign loopback HTTP service.

curl -i -X POST ' \

-H 'x-portkey-custom-host: \

--data '{"model":"test","messages":[{"role":"user","content":"probe"}]}'

The gateway constructs ` and relays the response or connection error. ` and ` work equivalently where those names resolve. Via the `proxyHandler` (`/v1/*` GET/POST/DELETE), the attacker further controls the method and path of the internal request. Do not run this against any third-party deployment.

Static source review at commit `669825cbe89ee51569918b8f78a9db486fd69dd4`, tracing the public route → `requestValidator`/`isValidCustomHost` → `customHost` context → URL construction → `fetch`. The default trusted-host short-circuit and the keyless Ollama path were confirmed in source. No code was executed and no live deployment was contacted.

- **Confidentiality (High):** read responses from HTTP services bound to loopback or reachable via `host.docker.internal` (other containers / the Docker host) - e.g. internal admin panels or APIs intentionally not exposed externally - and port-probe those destinations.

- **Destination limit (important):** by the default-trusted branch the primitive is restricted to `localhost`/`127.0.0.1`/`::1`/`host.docker.internal`/`*.localhost`. Arbitrary private-IPv4/IPv6 ranges, reserved IPs, cloud metadata (`169.254.169.x`), and blocked TLDs are rejected by the validator. This is not an arbitrary-internal-network SSRF.

- **Aggravating note:** the validator inspects the host **string**, not the resolved IP. A hostname that resolves to an internal address is not re-checked after DNS resolution, so DNS-based resolution to internal IPs (and rebinding) is a further bypass vector beyond the trusted set.

- Precondition: a self-hosted gateway reachable by the attacker and started without a narrowed `TRUSTED_CUSTOM_HOSTS`. Not claimed: RCE, or reaching hosts the validator rejects without a DNS trick.

- **Immediate:** make the default trusted-host set empty; require an explicit, narrowly scoped `TRUSTED_CUSTOM_HOSTS` for any custom host, and do not include loopback/docker-host by default.

- **Short-term:** enforce caller authentication/authorization before processing `/v1/*`; consider disabling `custom_host` for public-facing deployments.

- **Defense-in-depth:** resolve the host and validate the **resolved IP** immediately before connecting, and re-validate after DNS resolution to mitigate rebinding; apply the private/reserved/metadata blocks to trusted hosts too.

Do not trust loopback/docker-host by default for a request-controlled destination, and validate the resolved IP (not just the host string) before connecting.

- Project: [Portkey-AI/gateway](

- Source reviewed at commit [`669825c`]( `src/index.ts`, `src/middlewares/requestValidator/index.ts`, `src/handlers/services/requestContext.ts`, `src/handlers/services/providerContext.ts`, `src/handlers/retryHandler.ts`, `src/providers/ollama/api.ts`, `src/middlewares/requestValidator/schema/config.ts`

- Weakness: [CWE-918 Server-Side Request Forgery (SSRF)](

- Suggested CVSS 3.1: `8.6 (AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:N/A:N)`

Reported by hieuPenguinnn ([github.com/hieuPenguinnn](