Files
admin 9ebee9c96d fix(llm): 出站请求头默认不放行(allowlist),堵住网关 Key 经 x-api-key 泄漏
行业做法(LiteLLM / one-api / Higress 完全一致):**不由客户端决定**上游该收到哪些头,
而是网关按「上游需要什么」重新构造。nginx 侧对应 proxy_pass_request_headers off。

改造前实测(本机靶机 + .11 生产双确认):本块只覆写了 Authorization,客户端放在
x-api-key 里的**网关自己的 Key** 会被原样送给上游厂商,厂商可拿它反调本网关挂的
**全部**上游(横向越权)。MiniMax 两处都认,把这个缺陷掩盖成了 200。

改动:
- conf/nginx.conf 与两个测试模板:off + 凭据头显式抹空(x-api-key / api-key /
  x-goog-api-key,两层叠加,将来谁改回 on 仍兜底)+ 显式放行
  Content-Type / Accept / anthropic-version / anthropic-beta / openai-beta / User-Agent
- tests/llm/e2e.sh:+12 条断言。凭据头不泄漏、必需头存活(漏 Content-Type 会让所有
  POST 直接废)、以及 host 粒度 base 下一条记录吃 OpenAI + Anthropic 两种路径
- 反证:把模板还原成改造前状态(无 off、无抹空)重跑,3 条凭据断言如实变红(86/3),
  证明这组断言不是空转

回归:LLM 89 + 网关 78,失败 0。调研与实测证据见 docs/llm/UPSTREAM_PROTOCOL_AND_AUTH.md
2026-09-12 12:39:03 +08:00

59 lines
2.1 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ============================================================================
# LLM 代理 · HTTPS 回归配置模板(由 tests/run.sh 渲染并放进 @RUN@/tls/)
#
# 只在「本机 nginx 带 http_ssl_module 且 openssl 可用」时由 run.sh 生成,
# 否则整个文件不出现,nginx.conf.in 的空 glob include 等于没配。
#
# 与生产模板 conf/tls/llm.conf.example 的差异:端口 18443、自签证书、
# server_name _(本机无 DNS,靠 default server 兜住所有 Host)。
# ============================================================================
server {
listen 18443 ssl;
server_name _;
ssl_certificate @RUN@/tls/cert.pem;
ssl_certificate_key @RUN@/tls/key.pem;
ssl_protocols TLSv1.2;
client_max_body_size 100m;
location / {
ipass_llm on;
proxy_pass $llm_target;
proxy_http_version 1.1;
# 与生产 / 明文模板保持同一套出站头策略(默认不放行 + 凭据头抹空)
proxy_pass_request_headers off;
proxy_set_header x-api-key "";
proxy_set_header api-key "";
proxy_set_header x-goog-api-key "";
proxy_set_header Host $llm_host;
proxy_set_header Authorization $llm_auth;
proxy_set_header Content-Type $http_content_type;
proxy_set_header Accept $http_accept;
proxy_set_header anthropic-version $http_anthropic_version;
proxy_set_header anthropic-beta $http_anthropic_beta;
proxy_set_header openai-beta $http_openai_beta;
proxy_set_header User-Agent $http_user_agent;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Connection "";
proxy_buffering off;
proxy_request_buffering off;
proxy_cache off;
chunked_transfer_encoding on;
proxy_ssl_server_name on;
proxy_connect_timeout 5s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
}