mirror of
https://github.com/caddyserver/caddy.git
synced 2025-10-19 07:43:17 +00:00
chore: Use slices package where possible (#6585)
* chore: Use slices package where possible * More, mostly using ContainsFunc * Even more slice operations
This commit is contained in:
parent
9dda8fbf84
commit
2faeac0a10
21 changed files with 142 additions and 268 deletions
19
admin.go
19
admin.go
|
@ -34,6 +34,7 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
@ -675,13 +676,7 @@ func (remote RemoteAdmin) enforceAccessControls(r *http.Request) error {
|
|||
// key recognized; make sure its HTTP request is permitted
|
||||
for _, accessPerm := range adminAccess.Permissions {
|
||||
// verify method
|
||||
methodFound := accessPerm.Methods == nil
|
||||
for _, method := range accessPerm.Methods {
|
||||
if method == r.Method {
|
||||
methodFound = true
|
||||
break
|
||||
}
|
||||
}
|
||||
methodFound := accessPerm.Methods == nil || slices.Contains(accessPerm.Methods, r.Method)
|
||||
if !methodFound {
|
||||
return APIError{
|
||||
HTTPStatus: http.StatusForbidden,
|
||||
|
@ -877,13 +872,9 @@ func (h adminHandler) handleError(w http.ResponseWriter, r *http.Request, err er
|
|||
// a trustworthy/expected value. This helps to mitigate DNS
|
||||
// rebinding attacks.
|
||||
func (h adminHandler) checkHost(r *http.Request) error {
|
||||
var allowed bool
|
||||
for _, allowedOrigin := range h.allowedOrigins {
|
||||
if r.Host == allowedOrigin.Host {
|
||||
allowed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
allowed := slices.ContainsFunc(h.allowedOrigins, func(u *url.URL) bool {
|
||||
return r.Host == u.Host
|
||||
})
|
||||
if !allowed {
|
||||
return APIError{
|
||||
HTTPStatus: http.StatusForbidden,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue