From a82b5b1626715c42592e472daae6561503a12653 Mon Sep 17 00:00:00 2001 From: JianFeeeee Date: Wed, 26 Aug 2026 18:54:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(webui):=20/files/=20/uploads/=20=E9=9D=99?= =?UTF-8?q?=E6=80=81=E8=B7=AF=E7=94=B1=E6=8E=A5=E5=8F=97=20X-API-Key=20?= =?UTF-8?q?=E9=89=B4=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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。 --- internal/plugins/webui/handler.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/plugins/webui/handler.go b/internal/plugins/webui/handler.go index f2e5f0e..8499849 100644 --- a/internal/plugins/webui/handler.go +++ b/internal/plugins/webui/handler.go @@ -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)