Account takeover detection: how to spot credential stuffing, password spraying and session theft in your logs

Which login and session events to log, a recommended event schema, detection rules with example thresholds, how to respond without locking out real users, and how to keep it all GDPR-aware.

Obseria TeamObseria
Summary
  • Account takeover detection starts with complete, structured authentication events: every login attempt, MFA challenge, password reset, email change and session event with result, reason, IP, ASN, user agent and device.
  • Credential stuffing and password spraying look different in the data: stuffing produces many usernames and a low success rate per source, spraying produces few passwords across many accounts, and both often spread across many IPs.
  • Respond in steps rather than with hard lockouts: step-up authentication, throttling, session revocation and user notification, guided by the OWASP cheat sheets and NIST SP 800-63B.

Account takeover detection is the discipline of noticing, as early as possible, that someone other than the legitimate user is logging in to an account, or is trying to. The attacker might replay a list of leaked email and password pairs, guess one common password across thousands of accounts, or skip the password entirely by stealing a session cookie. In every case the evidence ends up in the same place: your authentication and session logs.

This guide explains the main attack types, which login and session events to log (with a recommended event schema), concrete detection rules with example thresholds, how to respond without locking out real customers, and how to keep the data GDPR-aware. It closes with a checklist you can copy. It complements our broader articles on security logging and audit logs and on SIEM versus observability, and focuses on the login path specifically.

Attack types behind account takeover

Account takeover (ATO) is the outcome; several techniques lead there. Knowing which one you face matters, because each leaves a different pattern.

  • Credential stuffing. Attackers take username and password pairs leaked from another service and try them automatically against yours, betting on password reuse. OWASP lists it as automated threat OAT-008. Signature: many different usernames, mostly failures, often one attempt per account, distributed over many IPs or residential proxies.
  • Password spraying. A small set of very common passwords is tried against many accounts, slowly, to stay below per-account lockout limits. Signature: many accounts, a low rate per account and evenly spaced failures. Never log the password itself.
  • Brute force. Many passwords against one account. Easy to see per account, and the classic reason for rate limits.
  • Phishing-based session theft. Adversary-in-the-middle phishing kits proxy the real login page, capture the password and the one-time code, and keep the resulting session cookie. The login itself looks successful and even shows MFA passed; the anomaly appears later, when the session is used from a different IP, ASN or user agent.
  • MFA fatigue (push bombing). With a valid password, the attacker triggers push notification after push notification until the user approves one. Signature: a burst of push challenges, several denials or timeouts, then an approval.
  • SIM swap. The attacker moves the victim's phone number to a new SIM and receives SMS codes. You rarely see the swap itself; you see an SMS-based login or reset from a new device, often followed by an email or password change. NIST SP 800-63B treats authentication via the public telephone network as a restricted authenticator for this reason.

Which login and session events to log

Most detection gaps are logging gaps. Many applications log failed logins but not the reason, log successful logins without the MFA method, or do not log session use at all. The OWASP Authentication Cheat Sheet asks you to log all authentication failures, password failures and account lockouts and to monitor them; for account takeover detection you need a little more. Log at least these events:

  • auth.login attempts, both success and failure, with a machine-readable reason
  • auth.mfa.challenge and auth.mfa.result (sent, approved, denied, timed out)
  • auth.lockout and auth.throttle when a control kicks in
  • account.password_reset.requested and .completed
  • account.email_changed, account.phone_changed, account.mfa_changed (factor added or removed)
  • session.created, session.refreshed, session.revoked, and session use from a changed IP or user agent
  • Sensitive actions: payout or bank details changed, API key created, export started, admin role granted

Emit these as structured logs with a stable schema rather than free text. Our guide to structured logging best practices covers field naming and levels in general; the table below is a recommended schema specific to authentication.

FieldExample valueWhy it matters
eventauth.loginStable name for queries and rules
user_id_hashHMAC-SHA256 of the user IDCorrelate per account without the plain identifier
username_existsfalseAttempts against non-existent accounts are a strong stuffing signal
resultfailuresuccess, failure, challenged, locked
reasonbad_passwordbad_password, unknown_user, mfa_denied, locked, throttled
client_ip203.0.113.17Per-source rates; truncate or hash for long-term storage
asnAS64500Groups distributed attacks from one hosting or proxy provider
user_agentRaw string plus parsed familyScripts often use rare or inconsistent agents
device_idRandom ID from a first-party cookieNew device versus known device
mfa_methodwebauthnnone, totp, push, sms, webauthn; weak methods deserve more scrutiny
geo_country, geo_cityDE, StuttgartImpossible travel and unusual countries; coarse is enough
session_id_hashHash of the session IDFollow a session across IP and user agent changes
trace_idW3C trace IDJump from the event to the full request

Never log passwords, one-time codes, session tokens or reset links, not even on failure. A failed password is often the user's real password with a typo, or their password for another service. Adding the trace ID lets you open the request trace behind a suspicious login and see exactly which endpoints the client touched afterwards.

Detection signals and rules

No single rule catches everything, so combine several cheap signals. The numbers below are examples to start from. Every application has a different baseline: a consumer app with millions of users and a B2B tool with 500 accounts need very different thresholds. Measure a few weeks of normal traffic before you alert on anything.

SignalDetectsExample rule (calibrate to your baseline)
Failed-login ratio per IPStuffing, brute forceAt least 20 attempts and failure ratio above 90 % in 10 min
Failed-login ratio per ASNDistributed stuffing via one providerFailures from one ASN above 5x its 7-day baseline in 15 min
Distinct accounts per IPStuffing, sprayingMore than 10 distinct usernames from one IP in 10 min
Share of unknown usernamesStuffing with leaked listsGlobal unknown_user share doubles versus the same hour last week
Global failure rateLow-and-slow attacks across many IPsLogin failure rate above 3x baseline for 30 min
Impossible travelShared or stolen credentialsTwo successful logins whose distance divided by time exceeds 1,000 km/h
New device plus sensitive actionTakeover in progressEmail, MFA or payout change within 30 min of a login from a new device
Password reset followed by email changeTakeover via reset or SIM swapBoth on one account within 1 hour
MFA push burstMFA fatigue3 or more denied or timed-out pushes within 10 min
Session reuse from different IP and user agentCookie theft, AiTM phishingSame session ID seen with a new ASN and a different user agent family

Two practical notes. First, impossible travel produces false positives from VPNs, mobile carriers and corporate egress points; combine it with a new device or a changed ASN rather than alerting on it alone. Second, the session reuse rule is often the only way to detect phishing kits that relay MFA, because the login itself was legitimate. It requires that you log session use, not only session creation.

A rule for distinct accounts per IP, written as generic SQL over your login events, could look like this:

-- example: possible credential stuffing, per source IP
SELECT client_ip, asn,
       count(*)                                   AS attempts,
       count(DISTINCT user_id_hash)               AS accounts,
       avg(CASE WHEN result = 'failure' THEN 1.0 ELSE 0 END) AS failure_ratio
FROM auth_events
WHERE event = 'auth.login'
  AND ts > now() - INTERVAL '10 minutes'
GROUP BY client_ip, asn
HAVING count(DISTINCT user_id_hash) > 10
   AND avg(CASE WHEN result = 'failure' THEN 1.0 ELSE 0 END) > 0.9;

Modern stuffing campaigns rotate through residential proxies so that each IP sends only a handful of requests. Per-IP rules then miss the attack, and the global signals (failure rate, unknown-username share, ASN baselines) become more important. This is where baseline-driven anomaly detection helps more than fixed thresholds. Also watch the success side: a stuffing run with a 1 % success rate still produces real compromised accounts, so list the accounts that logged in successfully from a source that was flagged.

Responding: step-up, throttle, lock and notify

Detection without a response plan produces either nothing or panic. Decide in advance which control applies at which confidence level.

  • Step-up authentication. The OWASP Credential Stuffing Prevention Cheat Sheet names multi-factor authentication as the most effective defense and suggests requiring it when risk signals appear, such as a new device, a suspicious IP or a high-risk action. Step-up is the right first response for a correct password in a risky context.
  • Rate limits and throttling. Limit attempts per account and per source, and add increasing delays. OWASP recommends graduated, temporary responses for IPs rather than permanent blocks, and CAPTCHA only for suspicious requests. NIST SP 800-63B (revision 4) requires verifiers to limit consecutive failed attempts on an account to no more than 100; that is an upper bound, and lower limits are allowed.
  • Lock versus throttle. Hard lockouts per account stop brute force but hand attackers a denial-of-service tool: lock everyone's account by sending wrong passwords. Prefer throttling with exponential delays and step-up, tie counters to the account rather than only to the IP, and let users recover through a secure reset flow. Keep error messages generic so that the login form does not reveal which usernames exist.
  • Session revocation. When a takeover is likely, revoke all sessions and refresh tokens for the account, not only the current one, and require re-authentication.
  • Notify users. Tell users about new-device logins, password and email changes, and about a correct password followed by a failed MFA check, which is a strong hint that their password is known. Send email-change notices to the old address. Show recent logins and active sessions in the account settings.
  • Breached-password checks. Both NIST SP 800-63B and OWASP recommend checking new passwords against lists of known compromised passwords. This reduces the number of accounts that stuffing can succeed against.

Route alerts by severity. A stuffing wave against the login endpoint is an incident for the on-call team; a single impossible-travel hit is a ticket for review. Handle confirmed takeovers with a defined process: our incident management process and postmortem template works for security incidents too.

GDPR-aware logging: pseudonymisation and retention

Authentication logs are personal data. IP addresses, device IDs, locations and account identifiers can all relate to an identifiable person. That does not prevent security logging, since protecting accounts is a legitimate purpose, but it shapes how you store the data.

  • Pseudonymise identifiers. Use a keyed hash (HMAC) for user and session IDs, with the key stored separately. A plain unsalted hash of an email address can be reversed by hashing a list of known addresses. Pseudonymised data is still personal data under the GDPR, but the risk is lower.
  • Minimise. Coarse geolocation (country, city) is enough for impossible travel. Parsed user agent family is often enough for long-term analysis.
  • Tiered retention. Keep full-detail events, including the full IP, for a short operational window, then keep aggregated or truncated data longer for trends and investigations. The right durations depend on your legal assessment and obligations; define and document them. See our glossary entry on retention.
  • Mask before storage. Apply PII masking in the telemetry pipeline, so that a developer who logs a request body by mistake does not put passwords or tokens into long-term storage.
  • Restrict access. Authentication logs are themselves a target. Limit who can query raw events and audit those queries.

Account takeover detection checklist

Copy this checklist into your security backlog

  • Login success and failure logged with a machine-readable reason, including unknown usernames
  • MFA challenges and results logged with method (push, TOTP, SMS, WebAuthn)
  • Password resets, email, phone and MFA changes logged as separate events
  • Session creation, refresh, revocation and use from changed IP or user agent logged
  • Schema with hashed user ID, IP, ASN, user agent, device ID, coarse geolocation and trace ID
  • No passwords, OTPs, session tokens or reset links in any log
  • Baselines for login volume, failure rate and unknown-username share per hour
  • Rules for failure ratio per IP and ASN, distinct accounts per IP and global failure rate
  • Rules for impossible travel, new device plus sensitive action, reset plus email change, MFA push bursts and session reuse
  • Step-up authentication on risk signals; throttling with exponential delays instead of permanent lockouts
  • Generic login error messages and consistent response timing
  • Breached-password check on registration and password change
  • User notifications for new devices, credential changes and failed MFA after a correct password
  • Runbook for revoking all sessions and recovering a confirmed compromised account
  • Pseudonymisation, PII masking and documented retention periods for authentication logs

How Obseria helps with account takeover detection

Obseria is an OpenTelemetry-native observability platform, so authentication events from your application arrive as structured logs alongside the traces and metrics of the same requests. You can build the detection rules above as queries and alerts, see login anomalies in the context of deployments and infrastructure, and follow a suspicious session from login to the endpoints it called. Application security in Obseria brings these signals together with runtime context.

  • Obseria Pipeline hashes user IDs, masks personal data and drops secrets before authentication logs are stored in the EU.
  • Baseline-driven alerting flags unusual failure rates and unknown-username shares without hand-tuned thresholds for every endpoint.
  • Obseria Lake keeps login events queryable for investigations, with retention you define per data type.

To see how your login events look in Obseria, book a demo.

Share

Observability that delivers answers.

Start for free with OpenTelemetry, no credit card required.