I'm currently hardening the security layer of my web appliocation, and I have some questions about the implementation of a login brute force protection :
What storage should I use to store the counter of failed login per user / IP ? Should a simple APC/Memcache entry be enough, or would it require a more stable and persistant storage method, also implying an extra SQL query or file write on every login ? Or even storing them in a session entry (my sessions are handled by Memcache, so it's quite the same).
The same question about the system-wide counter (in order to trigger a login lockdown or restriction in case of distributed brute force attemp... )? I think that the persistence here is more critical, but it also imply query/write on every login.
What would be the appropriate return response on a detected login brute force attemp ? Should I return an 404 error, an 503 Service unavailable ? Or even going deeper by DROPing or even TARPITing the attacker IP(s) through IPTables/Netfilter ? I'm talking about a real detected brute force attemp, not the case of a user failing some logins because he can't recall his pass.
I originally thought that a cache storage (APC/Memcache) would be enough to store the counter, but I'm fearing that the cache could fail for what reason, making this defense layer ineffective.
For every other considerations, I have already read some nice posts like What-is-the-best-distributed-brute-force-countermeasure and Number-of-attempts-to-brute-force-an-average-password, but feel free to throw any advice, it will be greatly appreciated.