Skip to content

Commit d095f1a

Browse files
samxu01claude
andcommitted
fix(litellm): strip CR/LF from provider API keys at startup (defense-in-depth)
A trailing newline in OPENROUTER_API_KEY (the GCP SM secret had been stored with one) made httpx reject the outgoing Authorization header ("Newline, carriage return, or null byte detected in headers. Potential header injection attack."), silently breaking ~half of the codex->nemotron fallback (2026-06-24). The source secret was fixed (newline stripped at the GCP SM source), but a malformed key from ANY source must never be able to break routing again. Sanitize the provider key env vars (OPENROUTER_API_KEY, OPENROUTER_API_KEY_2, OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY) by stripping CR/LF in the startup script before exec litellm; litellm inherits the cleaned env. Logs which keys it sanitized. Validated in POSIX sh. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 3610295 commit d095f1a

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

k8s/helm/commonly/templates/agents/litellm-deployment.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,20 @@ spec:
196196
else:
197197
print('LiteLLM chatgpt fail-fast patch: pattern not found (version changed?) - review needed')
198198
"
199+
# Defensive: strip stray CR/LF from provider API keys before litellm reads them.
200+
# A trailing newline in OPENROUTER_API_KEY (the GCP SM secret had been stored
201+
# with one) made httpx reject the outgoing Authorization header ("Newline,
202+
# carriage return, or null byte detected in headers. Potential header injection
203+
# attack."), silently breaking ~half of the codex->nemotron fallback (2026-06-24).
204+
# The source secret was fixed, but a malformed key from ANY source must never be
205+
# able to break routing again — so sanitize here too. litellm inherits this env
206+
# via exec below.
207+
for _k in OPENROUTER_API_KEY OPENROUTER_API_KEY_2 OPENAI_API_KEY ANTHROPIC_API_KEY GEMINI_API_KEY; do
208+
eval "_orig=\${$_k:-}"
209+
_clean=$(printf '%s' "$_orig" | tr -d '\r\n')
210+
[ "$_orig" != "$_clean" ] && echo "sanitized $_k (stripped CR/LF)"
211+
eval "export $_k=\"\$_clean\""
212+
done
199213
exec litellm --config /app/config.yaml
200214
ports:
201215
- name: http

0 commit comments

Comments
 (0)