2. If the connecting party (real TCP connection remote end) is in the trusted list, then take the rightmost address in XFF and set as remote end.
3. Repeat 2 until you get an address not in the trusted list.
4. That is now the real client IP. Discard anything to the left of it in XFF. (though maybe log it, if you want)
The article seems to forget the step of checking the real TCP connection remote address (from my skimming), which means that if the web server can be accessed directly, and not just through a load balancer that always sets the header, then the article is a security hole.
Deleted Comment
thought this was going down a P Diddy route there for a second
Instead of dropping, I maintain a list of trusted proxies, and I remove them from the list instead at the application level. The rightmost or final value is then the client.
Not dropping. Dropping what the client sent, and recreating it yourself, with the client connection's ip address. The IP can still be geolocated, as much as an ip address can be...
AS numbers have a very rough mapping to a very wide spot on a map, but they are not at all guaranteed to be accurate or up to date, and applied more so back when we had plenty of ipv4 space left and enormous blocks were held by giant companies.
Nowadays, ipv4 address are much more fragmented, globally, and an ASN might own a ip block that says the ip is in Utah, but it has since been leased out to some VPS provider who attached it to a load balancer running in a datacenter in Germany.
There are better headers (or better yet a combination of headers) that can be used to get the user's location, and their locale (yes, where you live or connect from doesn't at all mean you speak the native language in that region).
I'm sure plenty of lbs/reverse proxies and app servers don't set things, establish trust, or filter the header properly though, because, people, but it is easy to lock down.
Dead Comment
In some countries, maybe. In the US, there were concerted attempts (like the First Amendment to the Constitution) to prevent that from being the government's job, because of the fear that government would use that job to suppress dissent and coerce opinions.
If payment processors are picking up that job, and doing so in a coordinated manner that doesn't allow porn companies to simply say "use these payment rails to do business with us, not those ones," it is not unreasonable to suspect that they are doing so not for their own business interests but as a proxy for powers that the government is denied. Someone should be taking a long look at whether the US-based payment processors are becoming a tool of censorship and, if so, how that censorship is being coordinated. It's not like Visa and Mastercard come up with these things independently and on a whim.
Thank baby jebus that this sort of thing never happens. Can you imagine if our government were to, for instance, threaten to deport our own citizens, publicly, for disagreeing with the government. That would be a fucking shit show! Thank you, first amendment!
Deleted Comment
check into tailscale or cloudflare tunnels/argo