java-topology/defects/traefik/patch/traefik-0001-ip-checker-map.patch

38 lines
1.1 KiB
Diff

# UNDF: UNDF-2026-000000557
--- a/pkg/ip/checker.go
+++ b/pkg/ip/checker.go
@@ -11,8 +11,9 @@ import (
// Checker allows to check that addresses are in a trusted IPs.
type Checker struct {
- authorizedIPs []*net.IP
+ authorizedIPs map[[16]byte]struct{} // O(1) exact-IP lookup; was O(T) slice scan
authorizedIPsNet []*net.IPNet
}
@@ -23,8 +23,8 @@ func NewChecker(trustedIPs []string) (*Checker, error) {
}
- checker := &Checker{}
+ checker := &Checker{authorizedIPs: make(map[[16]byte]struct{})}
for _, ipMask := range trustedIPs {
if ipAddr := net.ParseIP(ipMask); ipAddr != nil {
- checker.authorizedIPs = append(checker.authorizedIPs, &ipAddr)
+ var key [16]byte
+ copy(key[:], ipAddr.To16())
+ checker.authorizedIPs[key] = struct{}{}
continue
}
@@ -78,11 +78,11 @@ func (ip *Checker) ContainsIP(addr net.IP) bool {
- for _, authorizedIP := range ip.authorizedIPs {
- if authorizedIP.Equal(addr) {
- return true
- }
+ var key [16]byte
+ copy(key[:], addr.To16())
+ if _, ok := ip.authorizedIPs[key]; ok { /* O(1) map lookup; was O(T) slice scan */
+ return true
}
for _, authorizedNet := range ip.authorizedIPsNet {