[Bug] 插件页面以 URL query 传递页面会话令牌(asset_token),凭据随访问日志与 Referer 扩散

Open
#11,197 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

Start with astrbot/dashboard/services/plugin_page_service.py and astrbot/dashboard/plugin_page_auth.py to trace asset token creation, TTL configuration, and scope checks; then inspect the plugin v1 route dependencies and the panel code that adds asset_token to request URLs. The issue identifies reducing and configuring the TTL as a minimal fix, while removing credentials from URLs or adding page scoped refresh would touch more paths. Done means the credential exposure is reduced as described and the permitted routes remain scoped to the plugin page.

Written by the indexing model from the issue text.

Description

bug
问题描述

面板加载插件页面时,把「页面会话令牌(asset_token)」以 URL query 参数下发:

  • GET /api/plugin/page/bridge-sdk.js?asset_token=<JWT>&theme=light
  • GET /api/v1/plugins/<plugin_name>/views/<view_path>/?asset_token=<JWT>&theme=light

该令牌为独立签发,不与登录会话共用同一枚 JWT:payload 含 token_type=plugin_page_asset、purpose=page_session、plugin_name、page_name、locale、iat、exp;但仍与登录会话共用同一 jwt_secret 签名。有效期由常量决定,当前 PLUGIN_PAGE_ASSET_TOKEN_TTL_SECONDS = 7 * 24 * 60 * 60,即整 7 天(astrbot/dashboard/services/plugin_page_service.py:26)。

作用域:astrbot/dashboard/plugin_page_auth.py 的 is_scope_valid() 仅在请求路径以 /api/plugin/page/bridge-sdk.js 开头时放行,其余路径一律拒绝该类令牌(源码注释:every other path rejects scoped asset tokens);插件 v1 路由另由其路由依赖做 scope 校验。因此该令牌不能调用通用 /api/v1/*。

因为凭据出现在 URL 里,它仍会被多处被动留存:

  1. 反向代理 / CDN 访问日志:nginx 默认 log_format 含 "$request",query 原样落盘(实测一个日志轮转周期内 6 条完整令牌);
  2. 浏览器历史、书签、「复制链接分享」;
  3. Referer:插件页面引用任何第三方资源(外链图片、字体、统计 SDK)时,完整 URL 随 Referer 外发;
  4. 排障截图 / 工单附件。

这些渠道的持有者可在有效期内用该令牌访问被 scope 允许的路由(bridge SDK 与该插件页面对应的 v1 路由),但不足以接管面板会话。

期望行为:

  1. 凭据不进入 URL / Referer / 访问日志;若因 webview 无法为静态资源请求设置 Authorization 头而必须走 query,应改为作用域受限的短期令牌——绑定单个插件页面、TTL 分钟级、可配置;
  2. 若一次性改造面较大,最小改动为把 TTL 从 7 天压到分钟级并支持配置;
  3. 长驻页面场景建议采用「短 TTL + 按页面 scope 刷新」的两层设计,而不是把单个令牌寿命拉长到 7 天。

参考:CWE-598(Use of GET Request Method With Sensitive Query Strings)。

如何复现?
  1. 部署 AstrBot 并登录面板(开启 TOTP 亦可,不影响复现);
  2. 安装任意带自定义页面的插件,在面板中打开该插件页面;
  3. 打开浏览器开发者工具 → Network,筛选 bridge-sdk.js 或 views/ 请求:可见 URL 上的 asset_token 为完整 JWT(三段式,eyJhbGciOiJIUzI1NiIsInR5cCI6… 开头);
  4. 作用域核对:该 token 对 /api/plugin/page/bridge-sdk.js 及该插件页面对应的 v1 路由有效,对通用 /api/v1/* 会被 scope 校验拒绝。因此本 issue 的关注点是「凭据进 URL 与 TTL 过长」,不涉及会话接管;
  5. 查看反向代理访问日志(或 CDN 日志),可见同一 URL 连同 token 被完整记录。
AstrBot 版本

v4.29.4-18-gf926af99e

操作系统

Linux

部署方式

源码部署(Python 3.14),由宝塔/GMSSH 的 Python 项目管理器托管进程,Nginx 反向代理 127.0.0.1:6185,HTTPS via 域名

使用的消息平台适配器

QQ官方机器人(WebSocket)

错误日志
本问题不是运行时异常,没有 traceback / Debug 栈;证据形态是反向代理访问日志中的请求行。下行为脱敏示例(JWT 与客户端 IP 已置换):

x.x.x.x - - [10/Nov/2026:15:51:52 +0800] "GET /api/plugin/page/bridge-sdk.js?asset_token=<JWT_REDACTED_eyJhbGciOi…len≈200>&theme=light HTTP/1.1" 200 2246 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) …"

x.x.x.x - - [14/Nov/2026:14:00:47 +0800] "GET /api/v1/plugins/<plugin>/views/<path>/?asset_token=<JWT_REDACTED>&theme=light HTTP/1.1" 200 7205 "-" "Mozilla/5.0 …"

同一轮转周期内共 6 条(2026-11-10 至 2026-11-15)。
另外说明:在自建运维脚本(非 AstrBot 本体)的运行日志中曾检出 5 条登录会话 JWT,原因是该脚本把登录响应整体打印;属第三方脚本问题,已自行修复并轮换了 jwt_secret,与 AstrBot 无关。
出于安全考虑,公开 issue 中不提交真实 token 与完整日志;如需完整样本可私密提供。
辅助信息

No response

检查清单
  • 我已在 Issue 列表 中搜索过相关问题仍无法解决,或该问题从未被报告过。
  • 我已尝试过禁用所有插件,排除了可能是因插件导致的问题。
  • 我报告的问题与 AstrBot 本体相关,而非在报告某一插件的问题。
  • 我已阅读并同意本项目的贡献者行为准则。
  • (可选) 我愿意提交 PR 以帮助修复该问题。

注:本正文已于 2026-11-17 按源码修正,原描述及撤回说明见下方评论。

Dominant language
Python
Stars
46.9k
Forks
3.6k
Avg merge
1d 6h
Merged PRs (30d)
136

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AstrBotDevs/AstrBot

All issues in AstrBotDevs/AstrBot

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.