Repository navigation
fix(dashboard): 其余 /api 写接口也拒绝跨站 Origin - #3002
Merged
Merged
Conversation
跨站门禁原先只匹配 /api/sessions/ 前缀和 /api/trigger、/api/asks/answer, 其余靠登录 cookie 鉴权的写接口(空 body 即可重启全部会话的 /api/update/restart、/api/update/run、/api/schedules 等)没有来源校验。 门禁改为对鉴权之后所有 /api/ 下的非读方法生效,仍只拒绝明确跨站的请求, 同源和无来源信号的非浏览器调用照常放行。
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
November 7, 2026 10:32
Owner
Author
首评结论:0 P1 / 0 P2,可合(2 个可选 P3)改动核对
P3(可选,不阻断)
验证
|
Owner
Author
|
已把最新 master 合入本分支(merge commit c02827e,未改写作者提交、未 force-push),主要为带入 #3076:此前本 PR head 首跑唯一红的 bun-test(mojo-task9 PROBE 2 死亡窗口 flake)已由 #3076 修复并合入 master。 合并树本地验证:bun run build(含 tsc)通过;dashboard-session-write-origin、dashboard-session-stop.integration、mojo-task9-probes 三个文件 vitest 61 测全绿,mojo 探针 bun 腿 7 测全绿。本 PR 的门禁改动在合并树中逐字保留。 新 head c02827e 的 14 项 CI 已开始首跑,等全绿后按流程复审合入。 |
Owner
Author
|
第二次同步 master(merge commit d67b3e4,仍未 force-push、作者提交保留),带入 #3116:上一轮本 PR head 首跑 bun-test 挂的 native-print #2347 do_exit 窗口 flake,已由 #3116(e8a18032c)用等价的 本次合并树本地验证:
新 head d67b3e4 的 CI 首跑已注册,等全绿后按流程复审合入。 |
|
🚀 Released in v3.59.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2932
问题
Dashboard 的跨站 Origin 门禁只覆盖
/api/sessions/前缀(#2876)和/api/trigger、/api/asks/answer两个精确路径(#2887)。其余靠登录 cookie 鉴权的写接口没有任何来源校验:登录 cookie 是 SameSite=Lax,同站不同端口、兄弟子域的页面发起的 POST 仍会带上它。影响最大的是POST /api/update/restart:body 为空时按普通重启处理,一个<form method=post>就能触发整台机器所有 bot 会话重启。/api/update/run、/api/schedules、/api/trigger-logs/prune、/api/groups/create、/api/skills/*等同理。复现:真实 Dashboard 进程上,带合法 cookie、
Origin: https://evil.example的POST /api/schedules拿到业务响应 400(已进入 handler),而不是 403。根因
src/dashboard/session-write-origin.ts的匹配条件是「/api/sessions/前缀 + 显式名单」,名单之外的写接口都不在门禁范围内。修法
把匹配条件改为「
/api/下的所有非读方法」(GET/HEAD/OPTIONS 之外),判定逻辑不变:仍复用controlRequestOriginState,只拒绝明确判为跨站的请求(外站 Origin、Origin: null、同站不同端口、Sec-Fetch-Site非 same-origin),同源放行,两个信号都缺席的非浏览器调用放行。旧的显式名单被覆盖,一并去掉。takeover / preview-interaction / locate 的一次性 CSRF 票据校验照旧叠加。影响面
/webhook/*、/api/federation/*(hub 侧,面向跨部署的服务端调用)、/__daemon/*、/__cli/*、/oauth/callback、H5 免登入口、插件结果页、workflow 侧栏、网页预览反代、终端反代/s/*、/__companion/*。BOTMUX_PUBLIC_URL、平台m-子域的同源判定与现有会话写接口完全一致(这些写接口自 fix(dashboard): 会话写操作统一拒绝跨站 Origin #2876 起已在同一套判定下运行)。桌面端不直接请求/api/。Origin/Sec-Fetch-Site(实测 Node 与 Bun 的 fetch 都不发这两个头),结果为「无来源信号」,照常放行。/api/trigger上就已被拒绝,现在扩展到全部/api/写接口。验证
null、Sec-Fetch-Site: cross-site/same-site)403 且不到达后端,同源与无来源信号 200;PUT/PATCH/DELETE 同样被拦;GET 与/api/之外的路径不受影响。/api/schedules、/api/trigger-logs/prune,带合法 cookie 也返回 403control_origin_forbidden。/api/update/restart只在单测里覆盖,没放进真实进程测试:旧代码上它会真的去走重启流程。