Merge pull request #3937 from opencloud-eu/fix/client-ip-no-trusted-proxies

fix(middleware): do not build the XFF middleware without trusted proxies
This commit is contained in:
Jörn Friedrich Dreyer authored and GitHub committed 2026-11-10 17:24:51 +01:00
commit 39493c1f37
1 file changed
+5
+5
View File
@@ -60,6 +60,11 @@ func ParseTrustedProxies(list []string) ([]netip.Prefix, error) {
// e.g. X-Real-IP or CF-Connecting-IP, it is its value. Without a usable
// header, e.g. on health checks, it is the address of the proxy.
func ClientIP(trusted []netip.Prefix, header string) func(http.Handler) http.Handler {
if len(trusted) == 0 {
// nobody may set the header, and chi's ClientIPFromXFF panics without
// a trusted prefix
return chimiddleware.ClientIPFromRemoteAddr
}
cidrs := make([]string, len(trusted))
for i, p := range trusted {
cidrs[i] = p.String()