Skip to content

fix(server): allow data and blob media fetches in CSP - #4434

Merged
wbxl2000 merged 1 commit into
mainfrom
fix/web-csp-media-connect
Oct 26, 2026
Merged

wbxl2000 merged 1 commit into
mainfrom
fix/web-csp-media-connect

Conversation

@kimi-agent-bot

Copy link
Copy Markdown
Collaborator

Requirement or Bug

修复非回环 Kimi Web 页面中 data/blob 图片无法复制或另存的问题。

Bug Reproduction Steps

  1. 以非回环地址启动 kimi web,使页面带上服务端 CSP。
  2. 打开一张以 data:image/... 表示的工具结果图片。
  3. 在图片预览中选择“复制图片”或“另存为”。
  4. 图片能正常显示,但 fetch(data:image/...) 被 default-src 'self' 拦截,操作失败。

Root Cause

img-src 'self' data: blob: 允许图片元素展示 data/blob 图片,但复制和另存需要先通过 fetch() 取得 Blob。CSP 未声明 connect-src,因此 fetch 回退到 default-src 'self',data/blob 请求被阻止。本次是对现有资源加载方式与 CSP 不匹配的根本修复,不是绕过错误提示。

Code Changes

 Content-Security-Policy
-  connect-src: 未声明,回退到 default-src 'self'
+  connect-src 'self' data: blob:
  • 保持其他连接目标不变,不新增外部 HTTP(S) 连接权限。
  • 更新 securityHeaders、securityExposure 和 hostExposure.e2e 的 CSP 契约。
  • 新增测试,明确 connect-src 仅包含 'self'、data:、blob:。
  • 增加 patch changeset。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
data/blob 图片复制和另存 非回环页面中的 fetch 被 CSP 阻止 与非回环页面同源及 data/blob 的 fetch 按既有代码执行 使用 LAN、反向代理或其他非回环绑定的 Web 用户 不需要;没有改变资源地址或调用路径
其他网络连接 继续受 default-src 'self' 限制 不变;未新增 HTTP(S) 或其他 scheme 的 connect-src 权限 依赖严格 CSP 的部署 不需要
回环页面 不下发这份 CSP 不变 本机 127.0.0.1 Web 用户 不需要

验证:

  • securityHeaders.test.ts、securityExposure.test.ts、hostExposure.e2e.test.ts:3 个文件、17 条用例通过。
  • pnpm --filter @moonshot-ai/kap-server run typecheck 通过。
  • 真实 MediaLightbox 生产组件对照:修复前出现“复制失败”及 data fetch CSP 错误;修复后纯 data 图片和 fileId/Blob 图片均成功进入剪贴板。
  • 两条路径读回的图片均为 640×360,解码像素 SHA-256 与源图完全一致;没有新增 CSP 错误。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete; no behavior is removed and no default is flipped.
  • Ran gen-changesets skill and included the approved patch changeset.
  • Ran gen-docs skill, or this PR needs no doc update. (No user documentation change required)

Requested by qer via Mira.

@changeset-bot

changeset-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 782efda

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T10:52:51.184910Z 782efda PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Oct 26, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@782efda
npx https://pkg.pr.new/@moonshot-ai/kimi-code@782efda

commit: 782efda

@wbxl2000
wbxl2000 merged commit f47400a into main Oct 26, 2026
17 checks passed
@wbxl2000
wbxl2000 deleted the fix/web-csp-media-connect branch October 26, 2026 11:26
This was referenced Oct 27, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
… as already landed

MoonshotAI#4434's CSP already allows data: and blob: media fetches, MoonshotAI#4517's
[workspace] require_trust section and its store short-circuit are in the
tree with both locale docs, and MoonshotAI#4605's tunnel scenario already reports
httpCapabilities and asserts the reconnected response.

Ledger: closed 28 -> 32, remaining 67.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants