The login page is one of the most attacked endpoints of any application. It constantly receives brute force attempts, credential stuffing with lists of leaked credentials and bot automation. A well-tuned WAF stops much of this abuse at the edge, before it consumes application resources or compromises accounts. The challenge is doing this without turning the login into a minefield for legitimate users.
Protection comes from combining rate limiting, reputation, challenges and login-specific rules. And each piece has to be tuned so it does not block real people, especially those who share the same corporate egress IP with the rest of the company.
Rate limiting and the care needed with shared IPs
Rate limiting defines how many attempts a source can make within a time window, which slows down brute force. The main caveat is that many legitimate users leave through the same IP. Think of an entire company behind a gateway, or a mobile carrier that puts thousands of subscribers behind a few addresses. An aggressive per-IP limit can block all of them at once. So tune the limit with that case in mind and, when possible, combine signals beyond the IP, such as session identifiers and behavior.
Credential stuffing is different from brute force. The attacker tests many username and password combinations, each only a few times, spread across many IPs. A simple per-IP limit catches this pattern poorly, because no single address ever goes over the ceiling. That is where IP reputation and automated behavior detection come in, since they look at the traffic as a whole instead of each source separately.
Window, limit and the action when it is exceeded
Every rate rule involves three decisions: the counting key, the limit within a window and what to do when the limit is reached. Counting by IP alone is the weak point in corporate environments, so whenever the platform allows it, build the key with another signal. Also prefer a graduated action. Instead of blocking the first time the limit is exceeded, apply a challenge, which separates humans from automation without punishing someone who just mistyped their password a few times. The sketch below shows the idea.
# Defensive pseudocode, adapt it to your WAF syntaxIF request.path == "/login" AND request.method == "POST": counting_key = combine(client_ip, session_token) limit = 10 attempts per 5-minute window on_exceed: apply_challenge # not an immediate block on_persist_after_challenge: block for a short periodThe numbers in the sketch are a starting point and do not apply to every application. Measure the legitimate traffic on your login before setting the limit. A short window with a limit that is too low ends up blocking real people, and a window that is too wide lets slow brute force through. Start by observing, then adjust with data from your own context.
Reputation, bots and challenges
IP reputation lists block sources known for abuse, and bot rules recognize automation from the characteristics of the request. Challenges, when the platform offers them, ask the suspicious client for proof before allowing the attempt. That lets you separate humans from automation without permanently blocking anyone. Use challenges in measured doses, because too much friction drives legitimate users away.
Where challenges help and where they get in the way
Well placed, a challenge is barely noticed by a human and is expensive for automation. The mistake is applying it to all traffic, because conversion drops and support fills up with complaints. Use the challenge only when there is a sign of suspicion (bad reputation, automated behavior, a rate above normal) and keep the path clear for whoever looks legitimate. Prefer challenges that do not depend on the user solving puzzles, since many of them filter out automation transparently, without the person noticing.
- Apply rate limiting calibrated for shared IPs
- Use IP reputation against sources known for abuse
- Detect automation with bot rules
- Apply challenges sparingly to suspicious traffic
- Combine signals beyond the IP, such as session and behavior
Signals beyond the IP to contain distributed stuffing
When the attack is spread across thousands of IPs, each with only a few attempts, the address stops being a good identifier. What still separates the campaign from real traffic is the overall pattern: an abnormal share of failed logins, a sudden volume of different usernames being tested, requests without the headers and the browsing sequence a legitimate client produces. A rule that looks at this aggregate rate, in addition to each source, catches what per-IP rate limiting lets through.
Add session and device signals to this. A client that passed the challenge and received a session token can move around with more leeway. One that always arrives with no cookie, no history and inconsistent headers deserves a closer look. The idea is to concentrate friction where the risk is, instead of imposing the same difficulty on everyone.
There is one more detail. A credential leaked in a public list gets tested on many services at the same time and, if your users reuse passwords, stuffing hits real accounts even with a well-tuned edge. In other words, account defense does not end at the edge, and the next section covers what the application needs to do.
The edge complements application controls
Edge protection reduces the volume of abuse, but the application still needs its own controls: progressive lockout after failed attempts, MFA, anomalous login detection and secure password storage with an appropriate algorithm. The WAF and the application work in layers. If you rely on the edge alone, the account is vulnerable the day a malicious request gets through.
Password storage and handling a suspicious valid login
Store passwords with a slow key derivation function designed for this purpose, with a per-user salt. If the database leaks, the person who obtains it still will not have the passwords in clear text. Also watch for the login that authenticates but deviates from the account pattern (an unusual country, a new device, an atypical time): in that case, require a second factor or an extra verification. Blocking the attempt does not help when the correct password arrives from a strange source, and that extra check is what protects the account.
Also standardize the login error messages so they do not reveal whether the user exists. A response that tells a wrong password apart from a nonexistent user hands the attacker half the work of account enumeration and weakens the very protection you are building.
Detecting and responding to credential stuffing campaigns
Monitor the login blocking metrics. A sudden spike usually indicates a campaign in progress, and the logs help you tune the rules and investigate the accounts that may have been affected. The most revealing metric is the authentication failure rate. In normal operation it varies little, and a sharp rise, especially across many different usernames, is the classic sign of stuffing.
- Volume of login attempts per minute and how it varies
- Authentication failure rate and number of distinct usernames tested
- Share of traffic that was challenged and failed
- Concentration of attempts by network range or by autonomous system
- Successful logins that deviate from the account's historical pattern
Have a plan ready for when the spike shows up: temporarily tighten the rate limit and the challenges, cross-check the logins against lists of known leaked credentials and, for accounts that authenticated during the campaign, force a password reset and end the active sessions. Afterward, record the incident and review the rules, because each campaign shows where the calibration was too loose.
Practical checklist
- Apply rate limiting calibrated for the login
- Account for shared IPs when setting limits
- Build the counting key with a signal beyond the IP, when possible
- Prefer a graduated action (challenge before block) when the limit is exceeded
- Turn on IP reputation against abusive sources
- Use bot rules to detect automation
- Apply challenges sparingly to suspicious traffic
- Monitor the aggregate authentication failure rate, not just each IP
- Keep MFA and progressive lockout in the application
- Store passwords with a slow derivation function and a per-user salt
- Standardize login error messages so they do not reveal accounts
- Require extra verification for a valid login with an anomalous pattern
- Monitor blocking metrics to detect campaigns
- Have a spike response plan: tighten rules, reset passwords, end sessions
- Tune the rules with an eye on the impact on real users
Best practices
- Calibrate limits with shared egress IPs in mind
- Combine signals beyond the IP to catch credential stuffing
- Use challenges sparingly and only on suspicious traffic
- Measure legitimate traffic before setting limits and windows
- Keep MFA and anomalous login detection in the application
- Treat the edge as one more layer, not the only one
- Watch the authentication failure rate as a sign of a campaign
- Review the rules after each incident and fix the calibration
Common mistakes
- Aggressive per-IP rate limits in a corporate environment
- They block many legitimate users who go out through the same gateway.
- Relying only on the IP against credential stuffing
- Attacks distributed across many IPs get past the barrier.
- Blocking at the first overage, with no graduated action
- It punishes people who just mistyped their password and adds friction for legitimate users.
- Too many challenges applied to all traffic
- High friction drives legitimate users away and hurts conversion.
- Error messages that reveal whether the user exists
- They make account enumeration easier ahead of the password attack.
- Relying only on the edge and ignoring the application
- Accounts become vulnerable when a malicious request gets through.
- Not monitoring the authentication failure rate
- Credential stuffing campaigns go unnoticed.
Authorship and review
Cesar Gargiulo
CEO and founder of GUARDIASEC. Technical and editorial lead for the content published in this library.
Published on . Found a technical error? Write to [email protected] and we will correct it and keep a record of the change.