admin: fix empty allowedPath regression and dead code in path normalization

path.Clean("") returns ".", so cleaning allowedPath unconditionally
silently broke the allow-all behavior when Paths: [""] is configured.
Short-circuit the empty case before cleaning to preserve that behavior.

Also remove the dead strings.HasSuffix(allowedPath, "/") branch —
after path.Clean the path never has a trailing slash, so the unified
reqPath == allowedPath || HasPrefix(reqPath, allowedPath+"/") form
covers exact match, subpath boundary, and trailing-slash requests.

Co-authored-by: atlarix-agent <agent@atlarix.dev>
Co-authored-by: iabdullah215 <muhammadabdullah8040@gmail.com>
This commit is contained in:
Amariah Kamau 2026-07-28 11:46:25 +03:00
parent 8a0651ad13
commit 7340171f99

View file

@ -724,18 +724,14 @@ func (remote RemoteAdmin) enforceAccessControls(r *http.Request) error {
func adminPathAllowed(reqPath, allowedPath string) bool {
reqPath = path.Clean(reqPath)
allowedPath = path.Clean(allowedPath)
if allowedPath == "" || allowedPath == "/" {
return strings.HasPrefix(reqPath, allowedPath)
}
if reqPath == allowedPath {
if allowedPath == "" {
return true
}
if strings.HasSuffix(allowedPath, "/") {
return strings.HasPrefix(reqPath, allowedPath)
allowedPath = path.Clean(allowedPath)
if allowedPath == "/" {
return true
}
return strings.HasPrefix(reqPath, allowedPath+"/")
return reqPath == allowedPath || strings.HasPrefix(reqPath, allowedPath+"/")
}
func stopAdminServer(srv *http.Server) error {