Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

[Bug] 知识库 API 全部返回 403:路由要求的 scope `kb` 不在 ALL_OPEN_API_SCOPES 白名单内

Open Beginner friendly
#10,322 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
api, authorization

Research direction

Start with astrbot/dashboard/api/knowledge_bases.py at require_kb_scope, then compare the scope definitions in astrbot/dashboard/services/auth_service.py with the validation in astrbot/dashboard/api/auth.py. Reproduce the request using an API key with kb or * scopes, align the route and permitted scopes, and verify that knowledge-base API calls no longer return 403.

Written by the indexing model from the issue text.

Description

问题描述

知识库相关接口(/api/v1/knowledge-bases/*)无法通过任何 API Key 调用,必然返回 403。

原因有两处互相矛盾:

  1. 知识库路由要求 scope 为 "kb";
  2. 但 "kb" 并不在 ALL_OPEN_API_SCOPES 白名单里,而校验函数在 scope 不在白名单时直接抛 403。

即:这个 scope 值在框架内无法被授予,因此该组接口对 API Key 永久不可达。仅通过 Dashboard 登录态(JWT)可访问,因为 JWT 分支直接授予 scopes=["*"]。

如何复现
  1. 创建一个 API Key,scopes 设为 ["kb"](或 ["*"]):
INSERT INTO api_keys (created_at, updated_at, key_id, name, key_hash, key_prefix, scopes, created_by, expires_at)
VALUES (..., '["kb"]', ...);
  1. 调用知识库接口:
curl -H "X-API-Key: $KEY" http://127.0.0.1:6185/api/v1/knowledge-bases
  1. 实际结果:
{"status":"error","message":"Insufficient API key scope"}

HTTP 403。即使把 scopes 设为 ["*"] 也一样 —— 因为在检查 scopes 内容之前,scope 本身先被白名单拦下了。

代码定位
期望行为

三选一即可:

  1. 在 DEFAULT_OPEN_API_SCOPES 中补上 "kb"(最小改动,与 file/data 等数据类 scope 一致);
  2. 或让知识库路由改用已有的某个 scope;
  3. 或让 Dashboard API Key 创建界面里可授予的 scope 与路由实际使用的 scope 对齐(当前界面无法覆盖 kb)。
影响

所有依赖知识库接口的自动化场景不可用:批量导入文档、从 URL 导入、检索、文档与分块增删查。

目前只能绕过 HTTP 层,在插件内部直接调用 context.kb_manager 完成同样操作,但这要求使用者自己写插件,普通用户无路可走。

环境
  • AstrBot 版本:4.28.2
  • 部署方式:Linux / systemd
  • 可稳定复现:100%

如判断有误(该 scope 存在其它授予途径而我未找到),欢迎指出。

Dominant language
Python
Stars
41.4k
Forks
3k
Avg merge
1d 14m
Merged PRs (30d)
135

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.