Security Hardening
LLM Proxy sits between your applications and paid upstream APIs, stores provider credentials, and serves an admin console. Review these settings before exposing it to the internet.
Credential model
| Credential | Storage | Notes |
|---|---|---|
API keys (sk-…) | SHA-256 digest | Plaintext shown once; used on /v1/* and /servers/* only. Keys are 256 random bits, so indexed SHA-256 lookup is sufficient |
| Console sessions | HS256 JWT, 24 h, no refresh, in an HttpOnly /api cookie | /api/* only; invalidated by password, role, or deactivation changes. Unsafe cookie requests require the X-CSRF-Token double-submit header |
| Playground session keys | HttpOnly /v1 cookie, 24 h | Browser-only transport for the console; explicit Authorization or x-api-key headers take precedence |
| User passwords | Argon2id (19 MiB), 8–72 chars with mixed character classes | Forced change for admin-created accounts; legacy bcrypt hashes are rehashed on next sign-in |
| Provider API keys | Fernet-encrypted at rest (enc: prefix) | Reveal is admin-only and audited; rotating ENCRYPTION_KEY makes stored keys unreadable |
| JWT / encryption secrets | Auto-generated, stored in the database | Protect database backups because they contain both secrets |
Edge and transport
| Item | Default | Recommendation |
|---|---|---|
| TLS | Terminates at your reverse proxy | Always use HTTPS in production; see Reverse Proxy & TLS |
| HSTS | on, max-age=31536000; includeSubDomains | Keep on; disable only for local HTTP development |
| Security headers | nosniff, DENY, Referrer-Policy, Permissions-Policy, CSP default-src 'self' (script/style allow unsafe-inline) | Sent by the app; no need to duplicate at the edge |
TRUSTED_PROXIES | RFC1918 + loopback + link-local | Set to your actual proxy networks. This replaces the default list. Spoofed X-Forwarded-For headers from untrusted peers are ignored |
| Request body limit | 64 MiB, enforced while streaming (chunked bodies are measured as they arrive) | Keep in sync with your reverse proxy's limit |
| CORS | Disabled (empty origin list) | Add only origins that need browser access |
Abuse protection
| Item | Default | Notes |
|---|---|---|
| Rate limiting | Enabled (in-memory) | rate_limit_disabled is the master throttle switch covering rate-limit buckets, per-key RPM, both failure lockouts, and the auth failure delay. It does not disable budget caps or request size limits. The UI warns when disabled |
| Shared rate limits | Off until REDIS_RATE_LIMIT_ENABLED=true | Required for multi-worker or multi-replica deployments. The memory backend keeps one window per process, so N workers allow N times the configured limit. Check GET /api/health → services.rate_limiting.backend to verify which store is active |
| Redis fail mode | redis_rate_limit_fail_closed=true | Blocks requests when Redis errors; safer for public deployments |
| Login lockout | Off by default. When enabled: 5 failures / 15 min per username | Off by default so an attacker who knows a username cannot lock out the account. Per-IP auth.login limits and the auth failure delay still apply |
| API-key IP lockout | Off by default. When enabled: 10 failures / 5 min per client IP | Off by default because one bad client can lock out everyone behind a shared NAT or corporate egress (and in local dev, all traffic is 127.0.0.1). Enable for instances exposed to untrusted networks. Applies to /v1/* and /servers/*; the auth failure delay still applies |
| Model allowlist rejection | 403, not counted as an auth failure | The key is already authenticated, so requesting a disallowed model does not trigger IP lockout or failure delay |
| WebSocket quotas | Budget checked before each billable turn | /v1/responses re-checks the key before every response.create; /v1/realtime checks before forwarding response.create and after each completed turn. Enforcement is best-effort because spend is cached for 15 s and usage is written asynchronously, so bursts or in-flight turns can overshoot the cap |
| Auth failure delay | 100 ms ±10% jitter | Slows brute-force attempts; keep enabled on public instances |
| Console auth buckets | auth.login 5/min, auth.setup 5/min | Tunable per bucket; see Server Settings → Rate Limits |
Keys, roles, and tenants
vieweraccounts cannot access provider, model, team, MCP, or settings APIs. Reserveadminfor operators.- Set expiry dates,
rate_limit_rpm, model allowlists, and budgets on every production key. An explicitly empty allowlist denies all models. - Account budgets cap total spend across all of a user's keys and can only be reset by an admin.
- Viewers see only their own logs and usage. API keys are owner-scoped even for admins, and stored Responses are namespaced per key so tenants cannot read or delete each other's records.
- For personal tracing, a non-admin's
base_urlmust be a public host; internal collectors must be listed inHTTP_ALLOWED_HOSTS. Admins keep the permissive self-hosted check. Demoting an admin to viewer clears their personal tracing configuration, after which they can re-add a public collector.
Outbound media downloads
A client-supplied image URL is fetched by the proxy in two cases: a chat message's image_url when routed to a provider that expects inline bytes (such as Ollama), and a Responses request's input_image when bridged to a provider that does not fetch remote images. Both use the same SSRF-validated fetch:
- Loopback, RFC1918, link-local, CGNAT, multicast, cloud metadata hosts, and URLs with embedded credentials are refused.
- Hostnames are resolved and every returned address is checked, so a public domain pointing to a private IP is refused.
- Up to five redirects are followed, and each hop is validated like the first. An
httptohttpsupgrade or CDN signing redirect works, while a redirect to127.0.0.1or a private host is blocked. - The response body is streamed and capped at
HTTP_MAX_DOWNLOAD_BYTES(20 MiB by default), matching the per-image ceiling of mainstream vision APIs. - Downloads for a single request are bounded as a group: at most four run concurrently, and total inlined payloads are capped at
HTTP_MAX_REQUEST_DOWNLOAD_BYTES(64 MiB by default, matching the request body limit). - On bridged Responses requests, a refused or failed download returns
400naming the URL. On chat requests, the failed image part is dropped and the request proceeds.
If you use internal image hosts or split-horizon DNS resolving to private ranges, list those hosts in HTTP_ALLOWED_HOSTS to exempt them. Scheme and credential restrictions still apply.
Outbound requests
Every URL the proxy fetches (provider base_url, personal tracing collector, remote MCP server, web-search endpoint, or client media URL) is SSRF-checked when configured. Requests made through the proxy's shared outbound HTTP client are checked again at connect time when using the default backend: its DNS resolver rejects private-network answers, preventing DNS rebinding. Redirect targets are resolved and checked in both backends. Literal IP addresses and localhost are checked at configuration time, and HTTP_ALLOWED_HOSTS exempts a host in both places. Setting HTTP_CLIENT_BACKEND=httpx2 keeps configuration-time and redirect checks without the connect-time resolver. Remote MCP servers, smart-routing clients, and Langfuse/OTLP/LangSmith exporters use configuration-time URL checks only.
Response sizes are also bounded:
- Buffered upstream responses are capped at
HTTP_MAX_RESPONSE_BYTES(64 MiB by default); larger responses fail with502. - Each line of a streamed SSE response is capped at 8 MiB.
- An MCP tool call, prompt, or resource result is capped at 8 MiB across its content blocks (
MCP_MAX_RESULT_BYTES); truncated payloads are marked so the model can tell.
MCP
MCP servers can run local commands and access the network, so the policy is deny-by-default:
- Allowlist the exact commands and environment variables each server needs. Shell metacharacters in arguments are rejected.
- SSRF protection resolves hostnames and rejects blocked IPs (loopback, RFC1918, link-local, cloud metadata, CGNAT) when a server is created or updated. This check runs at configuration time rather than at connect time. See Outbound requests.
- Keep
require_key_mcp_permissions=trueso each MCP server must be explicitly granted per API key. - Session slots are capped per configured MCP server per worker (1000 sessions, 10 min idle) to prevent
initializeloops from exhausting an endpoint. - Remote (
streamableHttp) servers cannot be given custom auth headers; prefer stdio or a controlled network path. - Every MCP call is logged with masked arguments in Logs → MCP Calls.
See MCP Servers.
Logging and privacy
- Request and response bodies are off by default (
log_input_output). Every row still records status, tokens, cost, routing, and audit metadata, while content payloads are stored as{"_bodies_disabled": true}(including request/response bodies, upstream error bodies, and MCP/web-search arguments and results). Error classification and stack traces are kept. Turn body logging on only when needed for debugging, then turn it back off. It is a master switch:x-log-full: truecannot override it for a single request. - Masking is on by default; add custom field names under Sensitive keys. Masked values keep their first 3 and last 4 characters (values of 8 characters or fewer become
***). The built-in set coversAuthorization,x-api-key,Cookie/Set-Cookieheaders, request/response bodies, and MCP/tool arguments. - Sampling reduces body capture (when body logging is enabled) without losing metadata. Sampled-out bodies are stored as
{"_sampled_out": true}, andx-log-full: trueforces full capture for a single request. - Retention defaults to 30 days for logs, audit logs, and usage records. Shorten it for sensitive workloads.
- Verify the audit chain regularly from Logs → Audit Logs → Verify Integrity and record the result. A failing chain indicates the audit history was altered.
- There is no bulk export endpoint; treat database access as access to all logs and restrict it accordingly.
Secrets and rotation
| Action | Consequence | Procedure |
|---|---|---|
| Rotate an API key | Affects only that key | Create replacement, switch clients, delete old key |
| Reset a user password | Revokes sessions; forces change at next sign-in | Admin: Team → Reset password |
| Rotate provider API keys | No downtime | Edit the provider (reveal is audited) |
Rotating JWT_SECRET invalidates all active console sessions. Rotating ENCRYPTION_KEY makes stored provider keys undecryptable until they are re-entered. Both are auto-generated on first run; see Upgrades & Backups → Secrets: what rotation breaks for backup and migration details.
Air-gapped or privacy-strict deployments
- Set
UPDATE_CHECK__ENABLED=falseto disable GitHub version checks. - Tracing is per-user and opt-in; leaving it disabled keeps request content inside your infrastructure.
- Web search and MCP are disabled or deny-by-default until explicitly configured.
Related
- Server Settings: security and rate-limit thresholds
- Logs, Usage & Tracing: audit verification
- Upgrades & Backups: secret persistence