robocanic commented on PR #1600:
URL: https://github.com/apache/dubbo-admin/pull/1600#issuecomment-7093150551
基于最新提交(`f911840b`)做了复核:之前提到的 JWKS 刷新期间单请求取消 / 失败导致 30s 批量 401 的问题已经通过
`context.WithoutCancel` + 独立超时 + stale 宽限期 + 5s 退避和对应单测修复。
目前还有以下几个需要修复/调整的点:
### 1. 前端 `refreshAfterUnauthorized(undefined)` 并发竞态会导致正常签发的 token 被丢弃(建议修复)
- **位置**:`ui-vue3/src/auth/accessToken.ts:61-68`
- **问题**:
```ts
async refreshAfterUnauthorized(rejectedToken: string | undefined):
Promise<string | undefined> {
if (!this.enabled) return undefined
if (this.token === rejectedToken) {
this.generation++
this.token = undefined
}
return this.getToken()
}
```
当 `this.token` 为 `undefined` 且已有进行中的 `this.refreshPromise`(闭包捕获旧
`generation`)时,如果另一个未携带 token 的请求触发
`refreshAfterUnauthorized(undefined)`,`this.token === rejectedToken`(`undefined
=== undefined`)会成立并执行 `this.generation++`,但没有清空 `this.refreshPromise`。随后
`this.getToken()` 会复用这个旧的 `refreshPromise`,等它 resolve 时因为 `generation !==
this.generation` 抛出 `AI access token issuance was discarded`,导致两个请求一起失败。
- **建议**:判断条件改为 `if (rejectedToken !== undefined && this.token ===
rejectedToken)`,或者在递增 `this.generation` 时同步重置 `this.refreshPromise =
undefined`(与 `clear()` 保持一致)。
### 2. AI 服务启用 JWT 认证后,非 loopback 监听仍被 `allow_insecure_static_auth` 拦截(建议修复)
- **位置**:`ai/component/server/component.go:109-121`
- **问题**:合入 `#1592` 的 `AuthenticationSpec` 后,`ServerComponent.Validate()` 在非
loopback 地址(如 `0.0.0.0`)上仍强制要求 `authentication.allow_insecure_static_auth:
true`,即使已经配置了 `auth.enabled: true`(Admin 与 AI 独立部署的典型场景)。这会导致开启 JWT
认证后仍必须显式开启一个名为 `allow_insecure_static_auth` 的配置项才能启动。
- **建议**:在 `Validate()` 中结合 `s.auth.Enabled` 处理(例如启用了 JWT 认证时不再要求必须开启
`allow_insecure_static_auth`),并补充对应单测。
### 3. `POST /api/v1/auth/token` 响应缺少 `Cache-Control: no-store` 头(安全加固)
- **位置**:`pkg/console/handler/auth.go:111-127`
- **问题**:签发 Bearer token 的响应未设置防缓存头,可能被中间代理或浏览器缓存。
- **建议**:返回前设置 `c.Header("Cache-Control", "no-store")` 和 `c.Header("Pragma",
"no-cache")`。
### 4. 配置校验与边界一致性(小问题)
- **`pkg/config/console/auth/config.go:139`**:`AccessTokenConfig.validate()`
中 `ActiveKeyID`、`Audiences`、`KeyID` 都做了 `strings.TrimSpace`,但 `c.Issuer == ""`
未做 `TrimSpace`(而 AI 侧 `ai/component/server/config.go:41` 做了 `TrimSpace`),建议统一改为
`strings.TrimSpace(c.Issuer) == ""`。
- **`ai/component/server/engine/auth.go:88`**:中间件已经挂载在 `/api/v1/ai` 路由组下,内部
`!strings.HasPrefix(c.Request.URL.Path, "/api/v1/ai/")` 属于 fail-open
的路径前缀放行,若未来挂载到其他路由组会静默跳过校验;建议改为仅放行 `OPTIONS` 和显式白名单路径(如 `/health`),默认拒绝。
- **PR 描述同步**:`f911840b` 已移除前端过期前主动续期逻辑(改为依赖 401 Bearer challenge
触发刷新),建议顺手更新 PR 描述中的 `"renews them before expiration"`,避免与实际行为不一致。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]