Skip to content

TB-003Bulletin

Rate limiting sign-in without locking out real users

Account lockouts stop the wrong attack and punish the wrong person. Count along several axes, give known devices their own budget, and answer with friction.

Farah HaddadHead of security, Amman

Title
Technical bulletin
Doc. no.
LM-09 / TB-003
Subject
Operations
Issued
22 Sep 2026
Reading
5 min

“Lock the account after five failed attempts” is the first rate limit everyone writes, and it fails in both directions. It lets anyone who knows your email address lock you out of your own account, and it does nothing against the attack you will actually receive, which makes one guess per account and never reaches five. Protecting a sign-in form means counting the right things and answering with friction, not with a locked door.

1.0Three attacks that look different in the logs

  • Brute force: many guesses against one account. Rare now, and the only one a per-account counter sees.
  • Credential stuffing: email and password pairs leaked from other sites, tried once each across thousands of accounts from thousands of addresses. Per account, it looks like one typo.
  • Password spraying: three or four very common passwords tried against every account, slowly, to stay under any per-account threshold.

In October, 0.9% of the sign-in attempts that reached Latch were refused by a limit. Fewer than one in five of those were aimed at a single account. A defence built on account lockouts would have missed the rest, and annoyed real users while doing it.

2.0Count along more than one axis

No single key catches all three. We keep several counters per attempt and act on whichever trips first. Each has a different response, because each means something different.

Default budgets for password and code sign-in. Counted on failures only.
KeyBudgetWindowResponse
Account + IP510 minDelay, doubling from 1 s to 30 s
Account, unknown devices201 hRequire an email code
IP, distinct accounts5010 minChallenge every attempt from that IP
Network (ASN)3× its baseline failure rate5 minChallenge unknown devices
Code sends per account51 hRefuse, with a retry time

The second and third rows do the real work. “Distinct accounts per IP” is the signature of stuffing and spraying. “Unknown devices” is what keeps the legitimate user out of the blast radius.

3.0Known devices get their own budget

When someone signs in successfully, we set a signed, HttpOnly cookie that says “this browser has signed in to this account before”. It is not a session and grants nothing. Its only job is to choose a counter. Attempts that present a valid device token for the account are counted separately from attempts that do not.

The effect is that an attacker hammering ines@palletline.io from a thousand addresses exhausts the unknown-device budget, and Ines, on the laptop she used yesterday, never notices. Her failures and theirs are in different buckets. This one mechanism removes most of the tension between security and lockouts.

Client
Edge
Latch
POST /sign-in
read counters
within budget: forward
verify password
failed: increment
401, same body as always
Fig. 3.1One failed attempt. The limiter runs before the password is checked, and updates after.

Attempt Email, password and, if the browser has one, a device token for that account.

Budget Known or unknown device, then the account, IP and network counters.

Pass Over budget, the request stops here with 429 and never costs a hash.

Check About 60 ms of argon2id. The expensive step is behind the limiter on purpose.

Count Only failures are counted. A success resets the account + IP counter.

Answer The same message and timing whether or not the account exists.

4.0A window that does not leak at the edges

A fixed window (“50 per ten minutes, reset on the tenth minute”) allows 100 in a few seconds if the burst straddles the boundary. A true sliding log is exact but stores every timestamp. The sliding-window counter sits between the two: keep the current and the previous window, and weight the previous one by how much of it still overlaps.

limiter.ts
export async function allow(key: string, limit: number, windowMs: number, now = Date.now()) {  const current = Math.floor(now / windowMs);  const elapsed = (now % windowMs) / windowMs; // 0..1 through the current window  const [here, before] = await store.mget(key + ":" + current, key + ":" + (current - 1));  const estimate = Number(here ?? 0) + Number(before ?? 0) * (1 - elapsed);  if (estimate >= limit) {    return { ok: false, retryAfter: Math.ceil((1 - elapsed) * (windowMs / 1000)) };  }  return { ok: true };}// Called after a failed attempt only.export const record = (key: string, windowMs: number, now = Date.now()) =>  store.incr(key + ":" + Math.floor(now / windowMs), { ttlMs: windowMs * 2 });

Two integers per key, one round trip, and the estimate is within a few percent of the exact answer for traffic that is not adversarially timed. For traffic that is, the error only ever lets through a small fraction more than the limit, never double.

5.0Answer with friction

  • Delay before deny. The first response to a tripped account + IP counter is a wait of 1, 2, 4 … up to 30 seconds, enforced on the server. A person retyping a password barely feels it. A script loses three orders of magnitude.
  • Step up before blocking. When an account's unknown-device budget is gone, the password stops being enough from unknown devices and an email code is required. The account is never locked.
  • Say when. Every 429 carries Retry-After, and <SignIn /> shows the countdown instead of a generic error.
  • Say nothing else. The same response body and timing for a wrong password, an unknown email and a disabled account.
Caution
Never lock an account on failed attempts alone. A lock that anyone can trigger with only an email address is a denial-of-service button, and attackers do press it, usually against your largest customer's admins.

6.0Codes and passkeys

A six-digit code has a million possibilities. With five attempts per code and a ten-minute life, one code gives an attacker a 5 in 1,000,000 chance. The limit that matters is therefore on sends: without it, an attacker asks for a new code every few seconds and gets five more tries each time. Five sends an hour holds the odds to 1 in 40,000 an hour per account, and the per-IP counter catches anyone spreading that over many accounts.

Passkeys have nothing to guess. A limit on passkey ceremonies protects your CPU, not your users, and can be generous. It is one more reason the long-term answer to credential stuffing is to have fewer credentials that can be stuffed.

Note
Every budget in the table is configurable per application. The defaults are the values we run on our own dashboard.

0.9%

Attempts refused by a limit

0.02%

Refusals that hit a real user

0

Accounts locked

Fig. 6.1 — Sign-in attempts on Latch, October 2026.

7.0Get started

Read enough. Try the part.

Everything in these bulletins is switched on in the free plan: passkeys, 60-second tokens, organizations and roles, for your first 10,000 monthly active users.

npm install @latch/nextjs

Included on Free

Monthly active users
10,000
Passkeys, codes, links
Included
Social providers
3
Organizations
5 members each
Card required
No