fix(security): prevent API key leakage to non-authoritative custom endpoints#28884
fix(security): prevent API key leakage to non-authoritative custom endpoints#28884erhnysr wants to merge 4 commits into
Conversation
…dpoints Custom endpoint provider was forwarding OPENAI_API_KEY and OLLAMA_API_KEY to arbitrary hosts. Keys should only be sent to their authoritative domains (openai.com, ollama.com) or when explicitly configured via pool/env. - Gate OPENAI_API_KEY to openai.com hosts only - Gate OLLAMA_API_KEY to ollama.com hosts only - Return 'no-key-required' for unrecognized custom endpoints - Update tests to reflect secure-by-default behavior Closes NousResearch#28660
|
Thanks for jumping on this. I did a local pass against this PR and the focused resolver file passes for me (
So I think the fix needs both pieces: gate provider env fallbacks in the named-custom paths too, while preserving |
- Preserve OPENROUTER_API_KEY for explicit mirror/proxy configs when requested provider is openrouter and OPENROUTER_BASE_URL is set - Gate OPENAI_API_KEY and OPENROUTER_API_KEY in named custom provider path (_resolve_named_custom_runtime) on authoritative hosts - Gate same keys in direct-alias path - Update tests to reflect secure-by-default behavior for local endpoints
|
Thanks for the detailed review @pmos69! Both issues addressed in the latest commit:
113 tests passing. |
|
Merged via PR #29606 — your two substantive commits were cherry-picked verbatim with your authorship preserved in git log. Thanks for the fix! We extended it with the bonus |
Problem
Custom endpoint provider was forwarding
OPENAI_API_KEYandOLLAMA_API_KEYto arbitrary hosts. A user pointing Hermes at a custom base URL (e.g. a local proxy or a lookalike domain) would silently send their real API keys to that endpoint.Closes #28660.
Fix
OPENAI_API_KEYis now only forwarded to hosts ending inopenai.comOLLAMA_API_KEYis now only forwarded to hosts ending inollama.comno-key-requiredunless a credential pool entry explicitly provides a keyTests
113 tests passing. Added/updated tests covering path injection attacks, lookalike hosts, legitimate Ollama Cloud, and OpenRouter mirror URLs.
Security Impact
Prevents credential exfiltration when users configure custom or self-hosted endpoints.