[Bug] "Fetch model list" is blocked by hardcoded CSP (connect-src 'self') for any non-Kimi provider
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- node.js, typescript
Hướng nghiên cứu
Grep for the hardcoded CONTENT_SECURITY_POLICY constant emitting connect-src 'self' data: blob:, then find the web server's route registration. The button logic is the client-side helper (pAe) in the web bundle that builds ${baseUrl}/models candidates; the preferred fix replaces it with a call to a new same-origin server route that reuses the stored provider config and API key. Read the provider config parsing first. Done means "Fetch model list" works for a custom OpenAI-compatible provider over a LAN address without widening CSP.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Environment
- kimi-code CLI
2.7.2(installed via officialinstall.sh, linux-x64) - Debian 13, headless server, no desktop environment
- Launched as
kimi web --host 0.0.0.0 --port 58627 --no-open - Web UI opened from another machine in the LAN:
http://192.168.9.154:58627/#token=... - Provider: custom OpenAI-compatible endpoint (
type = "openai",base_url = "https://api.deepseek.com/v1") configured in~/.kimi-code/config.toml
Steps to reproduce
- Run
kimi web --hoston a headless host and open the web UI from a different machine. - Go to Settings → the custom provider (
deepseek). - Click "Fetch model list" (获取模型列表).
Actual behaviour
The request never reaches the kimi server (server access log shows no corresponding entry at all). The browser blocks it before it is sent:
index-ATwV203V.js:39 Fetch API cannot load https://api.deepseek.com/v1/models.
Refused to connect because it violates the document's Content Security Policy.
at pAe (index-ATwV203V.js:39)
The document is served with:
content-security-policy: default-src 'self'; script-src 'self' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; connect-src 'self' data: blob:; font-src 'self' data:; form-action 'self'; base-uri 'none'; frame-ancestors 'self'
Root cause
The "Fetch model list" button performs the discovery request client-side: pAe({ type, baseUrl, apiKey }) in the web bundle builds candidate URLs (${baseUrl}/models, ${baseUrl}/v1/models, …) and calls them straight from the browser. Because connect-src is limited to 'self' data: blob:, every provider origin other than the UI's own origin is refused — i.e. the button cannot work for any custom/third-party provider in the kimi web deployment.
This is not a CORS problem and not a network problem:
- The identical request from the server host succeeds (
curl https://api.deepseek.com/v1/models→200, two models returned). - DeepSeek returns proper CORS headers for the UI's origin (preflight allows
authorization,access-control-allow-originechoes the origin), so it would be allowed if CSP did not block it.
Impact
In the primary headless/LAN deployment (kimi web --host), the discovery button is unusable for every non-Kimi provider. Users have to add models one by one by hand; when the upstream model catalog changes (e.g. DeepSeek now exposes deepseek-flash / deepseek-v4-pro instead of the older aliases) they get no way to discover it from the UI.
Expected behaviour
Clicking "Fetch model list" works for configured custom providers, or the failure is at least actionable / configurable.
Possible fixes (maintainer's call)
- Preferred: perform the discovery request server-side (the server already holds the API key and has network access), and return the model list to the UI over the same-origin REST API. This removes the CSP issue entirely and keeps the key out of the browser.
- Build
connect-srcdynamically from thebase_urlorigins of the configured providers. - Expose an env var / config key that appends origins to
connect-src(e.g.KIMI_CODE_CSP_CONNECT_SRC_EXTRA), so self-hosted deployments can allow their gateway.
Notes
- The policy is a hardcoded constant (
CONTENT_SECURITY_POLICY) with no env/config override; I enumerated allKIMI_CODE_*env vars and found nothing CSP-related. As a workaround I had to patch the binary with an equal-length string replacement (connect-src 'self'→connect-src *) to make the feature usable, which is obviously not something users should have to do, and it is reverted by every upgrade. - Related historical work:
#4434(allow data/blob media in CSP),#5185(allow HTTPS images),#1731(fix CSP on non-loopback binds) — so adjusting the policy for legitimate features seems to be accepted practice in this repo.
- Ngôn ngữ chính
- TypeScript
- Star
- 8.3k
- Fork
- 1.4k
- Merge trung bình
- 12 giờ 6 phút
- Pull request đã merge (30 ngày)
- 596
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của MoonshotAI/kimi-code
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
MoonshotAI/kimi-code#5539 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] Kimi RC workspace folder picker does not display symbolic link directoriesCó thể đã có người làm @markankamaransheogarat-sys đã nhận 2 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
MoonshotAI/kimi-code#5296 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
MoonshotAI/kimi-code#5256 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
MoonshotAI/kimi-code#5062 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
MoonshotAI/kimi-code#5057 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của MoonshotAI/kimi-code
Issue tương tự
-
Add Alice&BotĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
slavakurilyak/awesome-ai-agents#1048 ·
-
bot:ai-assisted component:faucet github_actions security status:untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
midnightntwrk/midnight-faucet-api#215 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[功能] 手机端命令执行显示 AI 动作描述Đang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
NanmiCoder/cc-haha#2034 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
mobile prio:low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
digitalfabrik/entitlementcard#3324 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày