mirror of
https://github.com/caddyserver/caddy.git
synced 2026-08-04 14:58:47 +00:00
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:
parent
8a0651ad13
commit
7340171f99
1 changed files with 5 additions and 9 deletions
14
admin.go
14
admin.go
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue