Skip to content

Commit 32bfd6f

Browse files
committed
fix(admin): reject unauthenticated requests when no bearer token configured
Previously, wrapAuthHandler passed all requests through when adminAuth.bearerToken was not configured, allowing the dashboard to accept any token via /v1/summary verification. Now the handler rejects all non-probe requests with 401, preventing fake token authentication.
1 parent 0259efa commit 32bfd6f

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

internal/admin/auth.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ func wrapAuthHandler(next http.Handler, opts Options) http.Handler {
3737
if opts.Logger != nil {
3838
opts.Logger.Warn("admin API running without authentication — set adminAuth.bearerToken or adminAuth.bearerTokenFile in config")
3939
}
40-
return next
40+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
41+
if isProbePath(r.URL.Path) {
42+
next.ServeHTTP(w, r)
43+
return
44+
}
45+
w.Header().Set("WWW-Authenticate", `Bearer realm="nantian-controlplane-admin"`)
46+
http.Error(w, "unauthorized", http.StatusUnauthorized)
47+
})
4148
}
4249

4350
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)