Nano Store - Ecommerce Docs
Developer ResourcesCatalog Integrity and Client IP

Login Brute-Force Throttling

Per-account and per-account-plus-IP login limits, the known-IP exemption, reset behavior, fail-closed rules, error codes and env keys.

Email login on the admin (web) and customer (mobile) surfaces counts failed attempts per account before it checks the password.

Behavior

  • Count first. One atomic Redis script increments every applicable counter before the user lookup and the password hash check. The attempt is rejected when any count exceeds its limit. A successful login refunds its own attempt.
  • Two counters, by IP trust.
CounterApplies toDefault limit
Per accountUnknown IPs only20 per 900 s
Per account + IPUnknown IPs5 per 900 s
Per account + IP (known-IP mode)IPs with a known marker10 per 900 s
  • Known-IP mode. A successful login sets a marker for that account and IP, valid for 30 days by default. While the marker exists, the login uses the gentler 10 per 900 s counter and does not touch the per-account counter. The owner on their known network gets 10 tries per 15 minutes and is locked for at most 15 minutes. A reset unlocks them immediately. An owner on their usual network is never locked by an attacker working from other IPs. The 900 s window caps guessing from a known address at 960 attempts a day, below the per-account cap.
  • Marker race. The known marker is written only if the account generation still equals the one read when the attempt was reserved. A reset between the reserve and the success leaves no marker under the new generation. A successful login clears and refunds the counters under the generation captured at reserve time, so the refund lands where the attempt was counted.
  • Accepted residual risk. An attacker can lock a known email for logins from new IPs. The owner on a known IP is unaffected. The API logs a warning when a per-account counter trips.
  • Unresolvable IP. When no trusted public client IP resolves, only the per-account counter applies. There is no per-IP counter, no known marker, and never a team-wide bucket.
  • Shared IP-tier key. Web and mobile login share one per-IP throttler key (LOGIN_ATTEMPT, 30 per 900 s per client IP), because the throttler keys on controller class and handler name and both controllers are @Controller("auth") with login/email. This is an accepted deviation from the original design.
  • Reset unlocks. Each account has a generation number. A successful password reset (by token or by OTP), a successful set or change password, and a superadmin password reset of a team member bump it. The superadmin reset releases the locks through team-member-password.ts, called from TeamService. The bump orphans every counter and known-IP marker of that account, so the next login is allowed immediately. A token or OTP reset also clears the set-password lock (the setpw-<realm> generation).
  • Mobile change-password. POST /api/mobile/user/change-password runs behind IpThrottlerGuard on the AUTH_ATTEMPT tier (5 per 15 minutes per IP), plus the per-user limiter. Its current-password check is limited by the setpw-customer realm, keyed on the customer id, before the password hash is compared. A success releases the customer's sign-in locks (the setpw-customer realm and the customer's email login realm; the email release is skipped and logged when the customer has no email). Over the limit it answers 429 AUTH_LOGIN_TEMPORARILY_LOCKED or the throttle's 429 RATE_LIMIT_EXCEEDED. If the limiter cannot count it answers 503 AUTH_LOGIN_UNAVAILABLE. During a Redis outage the guard fails first, so this route answers 500, not 503 (the AUTH_ATTEMPT tier has no store-failure option; follow-up 27).
  • Removed code. LocalStrategy and LocalAuthGuard are deleted. No importer remains.
  • Fail closed on the pre-check only. If the pre-check Redis call times out or errors, login answers 503 AUTH_LOGIN_UNAVAILABLE. Bookkeeping after the decision (refund, known marker, reset) logs an error and continues. A committed password reset never answers 503.
  • Redis outage on login-tier routes. Login-tier routes (web and mobile email login) answer 503 AUTH_LOGIN_UNAVAILABLE ("Sign-in is temporarily unavailable. Try again shortly.") when Redis is unreachable, including when the per-IP throttler guard is the first to fail (rejected command, error tuple or null result). Every other throttled route, including mobile change-password, keeps its 500 on a store failure.
  • Exception class. LoginLockedException extends RateLimitExceededException, so every limiter rejection is one class. It overrides getResponse() to return its own body.
  • Password oracle. The current-password check in set-password goes through the same limiter under its own realm, with no known-IP mode.

Error Codes

errorCodeHTTPHeadersRaised when
AUTH_LOGIN_TEMPORARILY_LOCKED429Retry-After: <seconds>A login counter exceeded its limit. Same body for every account state
AUTH_LOGIN_UNAVAILABLE503noneRedis could not be reached in time on a login-tier route (limiter pre-check or per-IP guard)

Retry-After is the longest remaining TTL among the counters that denied the request. The per-IP LOGIN_ATTEMPT tier 429 (RATE_LIMIT_EXCEEDED) now also carries Retry-After: 900. Branch on errorCode, never on message.

Body of the lock response:

{
  "message": "Too many sign-in attempts. Wait a few minutes and try again, or reset your password.",
  "errorCode": "AUTH_LOGIN_TEMPORARILY_LOCKED"
}

Configuration

All keys are optional. Values outside the bounds fail boot validation.

KeyDefaultBoundsPurpose
AUTH_LOGIN_FAIL_WINDOW_SECONDS9001 to 86400Window for the per-account and per-account+IP counters
AUTH_LOGIN_FAIL_MAX_PER_ACCOUNT_IP51 to 1000Failed attempts per account and IP
AUTH_LOGIN_FAIL_MAX_PER_ACCOUNT201 to 1000Failed attempts per account across unknown IPs
AUTH_LOGIN_KNOWN_IP_WINDOW_SECONDS9001 to 86400Window for the known-IP counter (was 300)
AUTH_LOGIN_KNOWN_IP_MAX101 to 1000Failed attempts per account on a known IP
AUTH_LOGIN_KNOWN_IP_TTL_SECONDS259200060 to 31536000Life of the known-IP marker (30 days)
AUTH_LIMITER_REDIS_TIMEOUT_MS1000100 to 5000Per-command timeout for the limiter Redis client
AUTH_LIMITER_REDIS_CONNECT_TIMEOUT_MS2000100 to 10000Connect timeout for the limiter Redis client

Production requirement

INTERNAL_CLIENT_IP_TOKEN is required when NODE_ENV=production; the API refuses to boot without it. It stays optional elsewhere. The value must match the admin deployment. Set it before deploying this release; see section 13.5 of docs/vps-deployment-runbook.md.

API_BIND_HOST is also required when NODE_ENV=production, and it must be a loopback or private address (RFC 1918, ::1 or fc00::/7). Otherwise the API refuses to boot.

If INTERNAL_CLIENT_IP_TOKEN is missing, admin traffic gets no per-address counter and no known-address pass. A stranger can then lock an admin out from new addresses.

The limiter keys on the trusted client IP the admin forwards, else on the direct peer when that is public, else on none. Loopback, private, link-local, unique-local and CGNAT peers never count as a client IP. A peer in a reserved range does not count either: ::, IPv4-compatible ::a.b.c.d, 0.0.0.0/8, 64:ff9b::/96, 2001:db8::/32, 198.18.0.0/15, 224.0.0.0/4 and above (including 240.0.0.0/4 and 255.255.255.255), and ff00::/8. Without a correct hop count and token, admin logins fall back to per-account limiting only.

Operator notes

  • Rotating the JWT signing key resets sign-in state. The account limiter key is derived from the JWT signing key (JWT_PRIVATE_KEY_BASE64). Rotating it orphans every sign-in counter, every lock and every known address at once. Plan a rotation knowing that locked accounts unlock and owners lose their known-IP status.
  • Error logs redact URL secrets. The global exception filter logs the request URL through redactUrlSecrets, so tokens in a query string do not reach the logs.
  • Token comparison. The internal client IP token is compared with timingSafeEqual over SHA-256 digests of both values, with no length branch.

Admin Copy

The admin login form shows these messages (branching on errorCode):

errorCodeHTTPMessage
AUTH_LOGIN_TEMPORARILY_LOCKED429Too many sign-in attempts. Wait a few minutes and try again, or reset your password.
RATE_LIMIT_EXCEEDED429Too many requests. Wait a few minutes and try again.
AUTH_LOGIN_UNAVAILABLE503Sign-in is temporarily unavailable. Try again shortly.

The admin does not relay Retry-After to the browser, so it shows no minute count.

Login Password Cap

The admin login uses its own DTO (AdminEmailLoginDto): password required, 1 to 1024 characters, no complexity rule. The mobile email login password cap also widens to 1024. Both are looser than before, so no existing client breaks.

Operations Log Lines

LineMeaning
login from internal peer without trusted client IPA login arrived from a non-public peer with no valid trusted header. Check admin TRUSTED_PROXY_HOPS and INTERNAL_CLIENT_IP_TOKEN. Logged at most once per 60 s per process
warn on x-internal-client-ip with a missing or wrong tokenToken mismatch between admin and API. Also at most once per 60 s per process
xff_resolution_failed (storefront)The storefront could not resolve the customer IP; its logins fall back to per-account limiting

See Also