Brute Force Protection and Rate Limiting for Login Endpoints
Quick answer
Protect login endpoints with layered defenses: rate limit by account and by source, slow down repeated failures progressively, require multi-factor...
Protect login endpoints with layered defenses: rate limit by account and by source, slow down repeated failures progressively, require multi-factor authentication where possible, and monitor for credential stuffing. Hard account lockouts stop guessing but can be abused to lock out real users, so prefer delays and step-up verification. Use generic error messages so attackers cannot tell which accounts exist.
What Attacks Are You Defending Against?
Login endpoints face two common patterns. In classic brute force, an attacker tries many passwords against one account. In credential stuffing, they try username and password pairs leaked from other breaches against many accounts, usually spreading attempts to stay under simple limits.
The distinction matters for design. A limit per account stops the first attack but does little against the second, where each account sees only a few attempts. A limit per IP address stops a single noisy source but is weak against distributed attacks that use many addresses. Effective protection combines several signals.
The goal is not to make attacks impossible but to make them slow and expensive enough, and visible enough, that they fail or are caught.
Which Rate Limiting Layers Should You Combine?
Use multiple independent limits, so bypassing one does not defeat the others.
- Per account: limit failed attempts for each username within a time window, regardless of source. This protects individual accounts from guessing.
- Per source: limit attempts by IP address or network range, which slows single-source attacks. Account for shared addresses, such as offices and mobile networks, so legitimate users are not penalized.
- Global: watch the total rate of failed logins across the system. A sudden spike signals a credential stuffing campaign even when no single account or address exceeds a limit.
- Per device or session: track known devices, and apply stricter checks to unfamiliar ones.
Store counters in a shared fast store, so limits apply across all application instances. Return a clear status such as 429 with a retry hint, but avoid revealing which limit was hit in a way that helps an attacker tune their behavior.
How Should You Handle Lockouts and Delays?
A permanent lockout after a few failures seems protective, but it creates a denial of service opportunity. An attacker can deliberately lock real users out by submitting wrong passwords for their accounts. Softer approaches avoid this.
- Use progressive delays that grow with consecutive failures, so guessing becomes impractical without blocking the real owner forever.
- Use temporary lockouts that expire automatically, and notify the account owner of suspicious activity.
- Require an extra verification step, such as a challenge or a one-time code, after repeated failures.
- Offer a safe recovery path that does not become a new attack surface.
Make sure the response is the same whether the account exists or not. Different messages or noticeably different response times let attackers enumerate valid usernames. Compare password hashes even for unknown accounts, or otherwise equalize timing, and use the same wording for every failure.
What Additional Controls Reduce Risk?
Rate limiting is one layer. Strengthen the whole login flow so that stolen credentials alone are not enough.
- Support and encourage multi-factor authentication, preferring phishing-resistant methods where available.
- Check new passwords against lists of known breached passwords, and enforce sensible length requirements, following current guidance such as the NIST recommendations.
- Store passwords with a slow, salted hashing algorithm, so a database leak does not expose them.
- Use bot detection or challenges selectively, for suspicious traffic rather than every user.
- Log failed and successful logins with source information, and alert on anomalies such as many accounts failing from one network or successes after many failures.
Consider notifying users about logins from new devices or locations, and give them a way to review and end active sessions. Test your defenses regularly and review the logs, since attackers adapt to whatever limits you publish.
Frequently Asked Questions
Should I lock accounts after five failed attempts?
Permanent lockouts can be abused. Prefer temporary lockouts, progressive delays, or step-up verification.
Is IP-based rate limiting enough?
No. Distributed attacks use many addresses, and shared addresses cause false positives. Combine it with per-account and global limits.
Should login errors be specific?
No. Use one generic message so attackers cannot learn which usernames are valid.
Does multi-factor authentication stop credential stuffing?
It greatly reduces its success, because a stolen password alone no longer grants access.
Summary
Layer per-account, per-source, and global limits, use delays and step-up checks over hard lockouts, keep errors generic, and add multi-factor authentication and monitoring. Consult current authentication guidance for specifics.