Interview Prep/Networking/Load balancers and reverse proxies

Rate limiting by client IP isn't working: attackers rotate the IP your app sees by sending their own `X-Forwarded-For` header.

AdvancedTroubleshootingLoad balancers and reverse proxies
Answer

Likely causes → The app (or nginx real_ip) takes the left-most XFF value, which the client fully controls. Or set_real_ip_from trusts 0.0.0.0/0, so any sender can set the "real" IP.

Diagnose →

curl -s -H 'X-Forwarded-For: 1.2.3.4' https://app.example.com/whoami
nginx -T | grep -E 'real_ip|set_real_ip_from'

If /whoami echoes 1.2.3.4, the header is trusted blindly.

Fix → Trust only your own proxies and take the right-most untrusted address:

set_real_ip_from 10.0.0.0/16;        # your LB subnets only
set_real_ip_from 173.245.48.0/20;    # e.g. CDN ranges, kept up to date
real_ip_header X-Forwarded-For;
real_ip_recursive on;

Prevent → Do rate limiting at the edge (CDN/WAF/ALB) where the TCP peer is the real client, and document which hops are trusted.

All Networking questions Roadmap: Networking for DevOps

More on Load balancers and reverse proxies