Open InterN0te opened 1 month ago
Added the real client IP as ClientID in Context and used this for IP abuse count/block/ban :
```go func ClientRealIP(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { clientID := GetClientIP(r) if(clientID == ""){ http.Error(w, "Invalid request", http.StatusBadRequest) return } ctx := context.WithValue(r.Context(), "ClientID", clientID) r = r.WithContext(ctx) next.ServeHTTP(w, r) }) } ```
```go func BlockByCountryMiddleware(blockedCountries []string, CountryBlacklistIsWhitelist bool) func(http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ip, ok := r.Context().Value("ClientID").(string) if !ok { http.Error(w, "Invalid request", http.StatusBadRequest) return } [...] } ```
(103.X.X.135 is my trusted proxy that can no longer be blocked)
Added TrustedProxies parameter in settings :
For requests from these IPs, the shield will use the IP in X-Forwarded-For (if defined) to identify the client to block and thus avoid blocking the proxy server IP