fix: 修复 Authorization header 鉴权失效等问题 (HTTP/WS 鉴权) + 版本 1.0.1 - #108
Merged
This-is-XiaoDeng merged 1 commit intoAug 13, 2026
Merged
Conversation
问题:uvicorn 按 ASGI 规范把 header 名转为小写存入 scope,而代码用 "Authorization" in request.headers.keys() 做大小写敏感判断,永远匹配不上, 导致所有用标准 Authorization: Bearer 头的 OneBot 客户端被 401 拒绝 (只有 ?access_token= 查询参数能过)。 修复: - authentication.py: 新增 get_bearer_token(),逐项比较 key.lower(), 不依赖 starlette 内部大小写行为;verify_access_token 改用它 - v11/http.py + v11/ws.py: 403/401 区分逻辑同样改用 get_bearer_token() - v11/v12 http/ws: check_access_token 警告条件反转(原来在已配置 token 时 反而报「未配置 Access Token !」) - v12/http.py: 鉴权判断反向(原来鉴权成功反而 401,自 PR ITCraftDevelopmentTeam#56 起一直如此) - pyproject.toml: 1.0.0 -> 1.0.1 验证:单元测试 6 例通过;源码运行真实登录后,Bearer header 200 / 错 token 403 / 无凭证 401 / query 参数 200
This-is-XiaoDeng
merged commit Aug 13, 2026
5add58b
into
ITCraftDevelopmentTeam:master
2 checks passed
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.
修复内容
1.
Authorization: Bearer鉴权完全失效(核心修复)Authorization: Bearer <token>头的 OneBot 客户端请求 HTTP API 永远得到 401;只有 `?access_token=*** 查询参数能通过scope,而verify_access_token用"Authorization" in request.headers.keys()做大小写敏感的成员判断 → 永远匹配不上get_bearer_token(),遍历headers.items()逐项比较key.lower(),不依赖 starlette 内部大小写行为;verify_access_token与 v11 HTTP/WS 的 401/403 区分逻辑全部改用它2. 「未配置 Access Token !」警告逻辑反转
check_access_token()在已配置 token 时反而报警告(条件缺not),v11/v12 的 HTTP 与 WS 服务器全部修正3. v12 HTTP 鉴权判断反向(历史遗留,自 PR #56 起)
handle_http_connection原来写的是if verify_access_token(...): raise 401—— 鉴权成功反而被拒,鉴权失败反而放行;已修正为if not ...4. 版本号 1.0.0 → 1.0.1(发布前置)
验证
200(修复前 401)403401200(无回归)get_version_info→app_version: 1.0.1