2015-01-14 12 views
6

che sto ottenendo il seguente errore sul mio Rails 4 applicazione:Come disabilitare l'IP Spoofing nell'applicazione Rails 4?

ActionDispatch::RemoteIp::IpSpoofAttackError: IP spoofing attack?! HTTP_CLIENT_IP="xx.xx.xx.xx" HTTP_X_FORWARDED_FOR="xx.xx.xx.xx"

Non abbiamo bisogno di questo tipo di controllo di sicurezza, così dopo un po 'di Googling in giro ho trovato questo:

https://github.com/rails/rails/issues/10780

When an intermediate proxy inserts the user IP address both in the HTTP_CLIENT_IP and the HTTP_X_FORWARDED_FOR, and this address is private, ActionDispatch::RemoteIp raises an IpSpoofAttackError exception.

When an enterprise proxy includes the user's IP address in a header, this will commonly be private. Removing private IP addresses from the chain contained in HTTP_X_FORWARDED_FOR should probably be done only when the address is not an exact match of the one found in HTTP_CLIENT_IP. If it is a match, that should be the user's IP address.

This happens for example with the following environment:

HTTP_CLIENT_IP: 172.17.19.51 HTTP_X_BLUECOAT_VIA: ffffffffffffffff HTTP_X_FORWARDED_FOR: 172.17.19.51 REMOTE_ADDR: xxx.xxx.xxx.xxx (this would be a public IP address)


una correzione qui presentata:

As a work-around, I've disabled this check in config/application.rb:

config.action_dispatch.ip_spoofing_check = false

Tuttavia, questo non sembra funzionare in Rails 4. Qual è la nuova chiamata e come posso impostarla sul sito?

risposta

5

Invece di disattivare l'avviso, potrebbe essere meglio risolvere il problema. Ecco la mia riformulazione di ciò che Rails è che ti dice:

This request seems to have come through two different reverse proxies. One of them set the CLIENT_IP header to the user's IP address; the other set the X_FORWARDED_FOR header. One of those values is probably correct, the other probably contains the IP of a reverse proxy, and I have no way to tell which is which. I can't reliably determine this user's IP address, so I'm going to reject the request.

La soluzione "corretta" è quello di fermare l'impostazione sia le intestazioni. Per questo dovrai rintracciare da dove vengono (inizierei con il tuo dispositivo Bluecoat) e scoprire se sono entrambi necessari. Solitamente userai solo l'uno o l'altro.

Se risulta che entrambi sono necessari (ho visto cose strane), quindi sarà necessario scoprire quale intestazione viene impostata per prima (supponendo che ci siano due proxy nella catena). Quindi puoi scrivere un middleware personalizzato che cancella l'altra intestazione HTTP.

Vedere Rails 3 middleware modify request headers per i puntatori su come creare il proprio middleware. Inseriscilo prima del middleware RemoteIp, cancella qualsiasi intestazione con il valore "cattivo" e dovresti essere bravo.