How to detect credential stuffing
Short answer
Compare your login logs with their normal baseline. Credential stuffing shows as a failure ratio well above usual, many attempts on accounts that do not exist, many usernames per IP address or device, a TLS fingerprint with an unusual failure rate or one that does not match its claimed browser, logins with no page load first, and successes followed at once by reads of saved addresses or cards.
A credential stuffing attack is hard to see in one request, because each attempt uses a real password from an ordinary-looking connection. It shows up in aggregates. Every signal below compares against your own normal, so first record a baseline for each by hour and weekday, with web, app and API logins kept apart.
The queries are PostgreSQL. They assume a login_events table with event_time, username, user_exists, success, ip, asn, device_fingerprint, ja4, user_agent and session_id, plus page_views and account_events tables keyed by session_id. All thresholds are starting points to tune against your traffic.
Is the login failure ratio above normal?
Real users fail logins through typos and forgotten passwords, so the raw count means little. The share of failures against the same hour last week is the first alarm. Watch the share of attempts on usernames that do not exist alongside it: stuffing lists come from other sites, so many of their emails were never registered with you.
WITH hourly AS (
SELECT date_trunc('hour', event_time) AS hour,
count(*) AS attempts,
count(DISTINCT ip) AS ips,
avg(CASE WHEN success THEN 0.0 ELSE 1.0 END) AS failure_ratio,
avg(CASE WHEN user_exists THEN 0.0 ELSE 1.0 END) AS unknown_user_ratio
FROM login_events
WHERE event_time >= now() - interval '8 days'
GROUP BY 1
)
SELECT cur.hour, cur.attempts, cur.ips,
round(cur.failure_ratio, 3) AS failure_ratio,
round(prev.failure_ratio, 3) AS failure_ratio_last_week,
round(cur.unknown_user_ratio, 3) AS unknown_user_ratio,
round(prev.unknown_user_ratio, 3) AS unknown_user_ratio_last_week
FROM hourly cur
LEFT JOIN hourly prev ON prev.hour = cur.hour - interval '7 days'
WHERE cur.hour >= now() - interval '24 hours'
ORDER BY cur.hour DESC;As a starting rule, alert when either ratio doubles against last week for two hours in a row and attempts are above a floor you set, so quiet nights do not page anyone.
How many usernames per IP address or device?
One person logs in to one account, sometimes two or three in a shared household. A device fingerprint or IP address that tries dozens of usernames in an hour is a tool working through a list. Attackers rotate IP addresses through residential proxies to keep each address to a few attempts, so count by device fingerprint as well. Check the ASN before acting on IP counts, because a mobile carrier or office address can carry many real users.
SELECT device_fingerprint,
count(DISTINCT username) AS usernames,
count(DISTINCT ip) AS ips,
count(*) AS attempts,
sum(CASE WHEN success THEN 1 ELSE 0 END) AS successes
FROM login_events
WHERE event_time >= now() - interval '1 hour'
AND device_fingerprint IS NOT NULL
GROUP BY device_fingerprint
HAVING count(DISTINCT username) > 5
ORDER BY usernames DESC
LIMIT 50;Run the same query grouped by ip. Then group by username and count distinct ip and device_fingerprint: one email tried from many addresses means the same list is being replayed, or several lists hold that email with different passwords.
Does one TLS fingerprint cover thousands of IPs?
A TLS fingerprint such as JA4 summarises how the client opens an encrypted connection (explained in TLS fingerprinting with JA3 and JA4). Every copy of the same browser version produces the same value, so a popular Chrome fingerprint on thousands of IP addresses is normal. What stands out is a fingerprint and user agent pair whose failure ratio is far above every other group, or a fingerprint that belongs to an HTTP library while the user agent claims to be Safari. Header fingerprints, built from the set and order of HTTP headers, work the same way.
SELECT ja4, user_agent,
count(DISTINCT ip) AS ips,
count(*) AS attempts,
round(avg(CASE WHEN success THEN 0.0 ELSE 1.0 END), 3) AS failure_ratio
FROM login_events
WHERE event_time >= now() - interval '1 hour'
GROUP BY ja4, user_agent
HAVING count(*) >= 100
ORDER BY failure_ratio DESC, ips DESC
LIMIT 20;What happens around a successful login?
A person opens the login page, then submits it. Many stuffing tools post straight to the login endpoint, so watch the share of web logins with no page view in the same session in the previous 30 minutes (native apps call your API directly, so leave them out). After a success, attackers check what the account holds: a read of saved addresses, payment methods or the loyalty balance within seconds, without visiting any other page. This query covers both checks:
SELECT l.event_time, l.username, l.ip,
EXISTS (
SELECT 1 FROM page_views p
WHERE p.session_id = l.session_id
AND p.event_time BETWEEN l.event_time - interval '30 minutes' AND l.event_time
) AS had_page_view,
(SELECT min(a.event_time) - l.event_time
FROM account_events a
WHERE a.session_id = l.session_id
AND a.event_type IN ('address_view', 'payment_methods_view', 'balance_view')
AND a.event_time > l.event_time) AS time_to_account_read
FROM login_events l
WHERE l.success
AND l.event_time >= now() - interval '1 hour'
ORDER BY time_to_account_read NULLS LAST
LIMIT 100;Successes with no page view and an account read under five seconds deserve a look first. Later steps of the takeover, such as email or payout changes, are covered in signs of account takeover.
What to do when the signals fire
Act when two or more signals agree. Challenge or block the cluster (the device fingerprints, or the TLS fingerprint and user agent pair) rather than single IP addresses, which the attacker replaces in minutes. List every account that logged in successfully from the cluster during the attack window, end those sessions and require a password reset. Check the password reset and mobile login endpoints too, since attackers move to whichever has the fewest checks. The prevention guide covers the longer-term controls.
Tools that help
StopBots is published by Kairal, which is one of the tools listed. The list is not a ranking.
- FingerprintJS is an open-source fingerprinting library whose browser identifier you can store with each login event to count usernames per device.
- CrowdSec is open source and bans IP addresses that repeat login failures in your server logs, which covers simple attacks for free but sees only per-IP patterns.
- Cloudflare Bot Management adds a bot score and TLS fingerprint fields to each request that you can log and group as in the queries above.
- Kairal detects credential stuffing from device, network and behavioural signals, and its console links the related events, devices and IP addresses behind each decision.
Common questions
What is a normal failed login rate?
There is no universal figure. Measure your own by hour of day and day of week over a few normal weeks, and keep separate baselines for web, mobile app and API logins, since they behave differently.
Can credential stuffing be detected from a single request?
Rarely. A request with a valid password from a residential IP address looks like the real user, so detection depends on patterns across many requests, or on device and connection details that the attacker's tooling gets wrong.
What should a login event record?
At least the time, the username as entered, whether the account exists, the result, IP address, ASN, user agent, a device fingerprint, a TLS fingerprint if your edge provides one, and a session ID. Never log the password, in clear or hashed.