@@ -328,7 +328,8 @@ func (m *Middleware) handlePhase(w http.ResponseWriter, r *http.Request, phase i
328328 // Whitelisting
329329 if m .CountryWhitelist .Enabled {
330330 m .logger .Debug ("Starting country whitelisting phase" )
331- allowed , err := m .isCountryInList (r .RemoteAddr , m .CountryWhitelist .CountryList , m .CountryWhitelist .geoIP )
331+ clientIP := getClientIP (r )
332+ allowed , err := m .isCountryInList (clientIP , m .CountryWhitelist .CountryList , m .CountryWhitelist .geoIP )
332333 if err != nil {
333334 m .logRequest (zapcore .ErrorLevel , "Failed to check country whitelist" ,
334335 r ,
@@ -360,7 +361,8 @@ func (m *Middleware) handlePhase(w http.ResponseWriter, r *http.Request, phase i
360361 // ASN Blocking
361362 if m .BlockASNs .Enabled {
362363 m .logger .Debug ("Starting ASN blocking phase" )
363- blocked , err := m .geoIPHandler .IsASNInList (r .RemoteAddr , m .BlockASNs .BlockedASNs , m .BlockASNs .geoIP )
364+ clientIP := getClientIP (r )
365+ blocked , err := m .geoIPHandler .IsASNInList (clientIP , m .BlockASNs .BlockedASNs , m .BlockASNs .geoIP )
364366 if err != nil {
365367 m .logRequest (zapcore .ErrorLevel , "Failed to check ASN blocking" ,
366368 r ,
@@ -377,7 +379,7 @@ func (m *Middleware) handlePhase(w http.ResponseWriter, r *http.Request, phase i
377379 return
378380 }
379381 } else if blocked {
380- asnInfo := m .geoIPHandler .GetASN (r . RemoteAddr , m .BlockASNs .geoIP )
382+ asnInfo := m .geoIPHandler .GetASN (clientIP , m .BlockASNs .geoIP )
381383 m .blockRequest (w , r , state , http .StatusForbidden , "asn_block" , "asn_block_rule" ,
382384 zap .String ("message" , "Request blocked by ASN" ),
383385 zap .String ("asn" , asnInfo ),
@@ -394,7 +396,8 @@ func (m *Middleware) handlePhase(w http.ResponseWriter, r *http.Request, phase i
394396 // Blacklisting
395397 if m .CountryBlacklist .Enabled {
396398 m .logger .Debug ("Starting country blacklisting phase" )
397- blocked , err := m .isCountryInList (r .RemoteAddr , m .CountryBlacklist .CountryList , m .CountryBlacklist .geoIP )
399+ clientIP := getClientIP (r )
400+ blocked , err := m .isCountryInList (clientIP , m .CountryBlacklist .CountryList , m .CountryBlacklist .geoIP )
398401 if err != nil {
399402 m .logRequest (zapcore .ErrorLevel , "Failed to check country blacklisting" ,
400403 r ,
0 commit comments