How Does a Rails App Know Client's IP

The story started when a colleague of mine asked about a weird error he got from Rails:

ActionDispatch::RemoteIp::Ip
SpoofAttackError: IP
spoofing attack?!

When I tried to help I learned how does Rails (in fact, Rack) “calculate” client’s IP. The problem is that our app might sit behind a number of proxy servers managed by us and by other people. I learned that there is an algorithm in HTTP protocol to get trusted client IP in those cases.

Lightning talk from Minsk.rb 17 (in Russian):