Skip to content

修复 #286 D4:接口令牌文件读回 embed 被 CF 注入污染 - #326

Merged
todosdev[bot] merged 1 commit into
mainfrom
tds/conv-01a22654-570c-7291-9884-41fccd9cb428
Nov 29, 2026
Merged

todosdev[bot] merged 1 commit into
mainfrom
tds/conv-01a22654-570c-7291-9884-41fccd9cb428

Conversation

@todosdev

@todosdev todosdev Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • 修复 htmlEmbed 嵌入内容跟随站点主题(阅读态下发 + 注入脚本 + 契约文档) #286:Agent 经 GET /api/read/files/<key>.html 读回 embed 时,CF 会对 text/html 响应注入 challenge 脚本,非浏览器客户端(curl/Node fetch)无 cf_clearance 必拿到污染字节,照 agent-guide §11 重传即污染 R2、多轮迁移逐轮膨胀。
  • 将 embed 文件读回的 Content-Type 强制为 application/octet-stream,字节即 R2 真身;图片/场景 JSON 读回保持原 Content-Type 不变。

Changes

  • worker/src/routes/read.ts:文件读回端点对 EMBED_KEY_RE 命中者强制 application/octet-stream,其余沿用 R2 httpMetadata.contentType;同步更新端点 JSDoc 并加根因注释。
  • worker/test/read-api.test.ts:embed 读回断言从 text/html 改为 application/octet-stream,保留 read/write 双令牌逐字节一致断言。
  • docs/agent-guide.md:§4.3 与 §11「拉取字节」各补一句,说明 embed 读回 Content-Type 为 application/octet-stream、字节即 R2 真身(无 CF 注入),按字节原样重传即可。

Testing

  • 本地:pnpm exec tsc --noEmit、pnpm build 通过;pnpm exec vitest run test/read-api.test.ts 21 用例通过;pnpm test 全绿(868 单测 + 23 workers 用例)。
  • CI:workflow_dispatch run 46242739996,conclusion=success,head_sha=1643df7,Lint / Format / Type check / Build / Test / Check deploy config 全绿。

未改授权逻辑、key 形状校验、鉴权中间件与浏览器通道(files.ts 仍按 text/html + CSP 下发)。本 diff 不含需重建的打包产物(worker build 为 tsc --noEmit,web 构建产物不进仓库)。

@todosdev
todosdev Bot merged commit bb91ee5 into main Nov 29, 2026
2 checks passed
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.

1 participant