Fall back to session cookie on stale Bearer key and report authVia #153

Merged
weichen merged 1 commits from feature/admin-auth-gate-fix into main 2026-10-11 13:48:25 +00:00
Owner

Why: 浏览器 localStorage 残留已吊销 API key 时,Bearer 优先级让有效登录会话也全部 401,管理员被锁在用户管理之外;/api/me 对 key 凭证也报 mustChangePassword,而 key 不能改密(会话专属),强制改密门成为死路。

改动:

  • 中间件:失效 key 回落有效会话 cookie 再 401(不带 cookie 的程序化客户端行为不变)
  • /api/me 增加 authVia(key/session/空)

Evidence: 新增 TestStaleKeySessionFallback(回落 + authVia);go test ./... 全绿(SELF,待 CI GATE)。

Refs: Dev 任务 feature/admin-auth-gate-fix(组合验证与 gitlink PR 在 Dev 仓推进)。

**Why:** 浏览器 localStorage 残留已吊销 API key 时,Bearer 优先级让有效登录会话也全部 401,管理员被锁在用户管理之外;/api/me 对 key 凭证也报 mustChangePassword,而 key 不能改密(会话专属),强制改密门成为死路。 **改动:** - 中间件:失效 key 回落有效会话 cookie 再 401(不带 cookie 的程序化客户端行为不变) - `/api/me` 增加 `authVia`(key/session/空) **Evidence:** 新增 `TestStaleKeySessionFallback`(回落 + authVia);`go test ./...` 全绿(SELF,待 CI GATE)。 **Refs:** Dev 任务 feature/admin-auth-gate-fix(组合验证与 gitlink PR 在 Dev 仓推进)。
weichen added 1 commit 2026-10-11 13:46:08 +00:00
Fall back to session cookie on stale Bearer key and report authVia
ci / vet-and-test (pull_request) Successful in 44s
6681c3b47c
Why: a browser holding a revoked API key in localStorage sent the Bearer
header on every request; key precedence 401'd all APIs despite a valid
login session, locking admins out of user management. /api/me also
reported mustChangePassword for key principals, who cannot change
passwords (session-owned), dead-ending the forced-change gate.

Evidence: new TestStaleKeySessionFallback covers fallback and authVia;
TestAuthMiddleware/TestAdminAccountFlow unchanged and green; full
go test ./... green.

Impact: invalid key falls back to a valid session cookie before 401
(cookie-less programmatic clients unaffected); /api/me gains
authVia ("key"|"session"|""), letting the frontend keep key holders
out of the change-password gate.

Refs: Dev task feature/admin-auth-gate-fix.
weichen merged commit 51ad3ce115 into main 2026-10-11 13:48:25 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: weichen/Agent-System-Backend#153