Well, you can rely on environmental variables to check the IP of the machine connecting to the server, as it's set by your local webserver. (assuming you trust your local webserver, that is.) Yes, there are issues, but I don't think it's worth ruling them out -- for authentication yes, not it can still be used for authorization, if you know where the problems are.
HTTP_ADDR is very reliable. However, the problem comes that it might not be the IP for the machine that the person is connecting from.
Many proxies will also set X_FORWARDED_FOR, but they're not required to, and those IP addresses aren't necesarily routable, which means that a collision in non-routable space may not be a collision for different proxy servers.
If you're just looking for _some_ sort of rate throtling (ie, better than nothing at all), I'd use a combination of HTTP_ADDR, and X_FORWARDED_FOR. I'd probably not worry about the issues with non-routable colisions, and keep track of the following:
if ( defined $ENV{'X_FORWARDED_FOR'} ) {
&track(':'.$ENV{'X_FORWARDED_FOR'});
&track{$ENV{'HOST_ADDR'}.':'.$ENV{'X_FORWARDED_FOR'});
} else {
&track{$ENV{'HOST_ADDR'});
}
(specific tracking code depends on what you're planning, how much memory you have, and what other resources (ie, database), you have available.)
Now, let's look at the flaw in my plan -- anyone can send whatever they want in X_FORWARDED_FOR, which would suggest they're a proxy server, and you'd not be rate limiting them if they put something random in it. (it's possible that the original poster would want to rate limit proxy servers at some smaller interval, just to keep the 10,000 possibility down).
Personally, I'd just impose extra sleep for those times of collisions in the case of a proxy -- if you slow it down to one every 30 seconds or so, it makes it less likely that it'll get abused. (and remember that in whatever tracking system you're using, log at the time that it comes in, but set the timestamp to the time that it's expected to run, so if something else comes in while it's sleeping, it won't just wait ($time), it'll wait $time past the current one finishing.
Just remember -- anything you can do will never making spamming impossible. You juat need to make things harder on the spammer so they'll try somewhere else -- hopefully, without imposing too much of a burder on your legitimate users. |