fix(webui): /files/ /uploads/ 静态路由接受 X-API-Key 鉴权

requireWeb 此前只认 cookie session,ArkTS/GUI 等 API key 客户端
加载 agent 输出的附件 URL(/files/xxx、/uploads/xxx)一律 302 到
/login。现 requireWeb 先校验 validAPIKey 放行非浏览器客户端;
无凭证仍 302 登录页,行为不变。

handleFiles/handleUploads 已有严格防穿越(拒 / \ ..),暴露给
key 客户端安全面可控。

端到端验证:X-API-Key 访问 files/uploads 均 200,无凭证 302。
This commit is contained in:
JianFeeeee
2026-08-26 18:54:26 +08:00
parent 2d5d246606
commit a82b5b1626

View File

@ -720,6 +720,13 @@ func (h *Handler) requireAPI(fn http.HandlerFunc) http.HandlerFunc {
func (h *Handler) requireWeb(fn http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// API key 客户端ArkTS/GUI 远程连接)与 cookie session 同等放行:
// agent 输出的 /files/、/uploads/ 附件 URL 会被非浏览器客户端直接加载,
// 它们没有也不应有 web 登录态。
if h.validAPIKey(r) {
fn(w, r)
return
}
_, username, password, _ := h.getWebUIConfig()
if username == "" || password == "" {
http.Error(w, "webui username/password not configured", http.StatusServiceUnavailable)