Constrain playground custom-model endpoint/api_key_env to server-declared pairs - #27
Merged
Merged
Conversation
…ared pairs Custom models registered via the viewer playground API are browser-controlled state, but their `endpoint` and `api_key_env` were forwarded unvalidated into litellm. An attacker could register a model pointing `endpoint` at their own host and `api_key_env` at any process env var, causing the resolved secret to be POSTed to the attacker (secret exfiltration) or the server to make requests to internal/metadata addresses (SSRF). Harden the boundary: - registry.resolve_api_key_from_config: validate api_key_env against a shell-style env-var regex and accept an optional allowed_env_vars allowlist. - viewer.trace_routes: custom models may only reuse (endpoint, api_key_env) pairs declared in the server-side models config (or provider defaults). Enforced on write (400) and stripped on read; run_inference resolves keys only from the known api-key allowlist. Extracted from 0001-playground-model-boundary of the security hardening set. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
sklinglernv
force-pushed
the
security/playground-model-boundary
branch
from
July 27, 2026 10:10
f404877 to
3cc0919
Compare
Collaborator
|
LGTM! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a secret-exfiltration + SSRF vulnerability in the viewer playground.
Custom models registered via the playground API (
POST /api/playground/models) are browser-controlled state, but theirendpointandapi_key_envwere forwarded unvalidated intolitellminrun_inference:An attacker who can reach the viewer could register a model where:
endpoint→ their own host andapi_key_env→ any process env var (e.g. a cloud/DB secret) → the resolved secret is sent to the attacker (secret exfiltration), orendpoint→http://169.254.169.254/...or an internal service → SSRF into the metadata service / internal network.Fix
Custom models may only reuse an
(endpoint, api_key_env)pair the operator already declared server-side inmodels.yaml(or provider defaults) — never invent one.unifiedllm/registry.py—resolve_api_key_from_configvalidatesapi_key_envagainst a shell-style env-var regex and accepts an optionalallowed_env_varsallowlist (defense-in-depth for callers handling untrusted config).viewer/trace_routes.py— trusted pairs are built from the server-side models config; enforced on write (HTTP 400) and stripped on read (get_playground_models,get_model_config).run_inferenceresolves keys only from the known api-key allowlist.load_custom_modelsalso gains a type-confusion guard.Extracted from
0001-playground-model-boundaryof the security-hardening patch set (the other patches in that set cover unrelated issues and are not included here).Testing
uv run pytest).pairsset annotation).🤖 Generated with Claude Code