Skip to content

Rate Limits

Rate limiting protects authentication endpoints from brute force attacks, credential stuffing, and email bombing. All limits are tenant-scoped (per-environment) with global safety nets to prevent cross-tenant abuse.

┌─────────────────────────────────────────────────────────────────┐
│ Request Flow │
├─────────────────────────────────────────────────────────────────┤
│ 1. Preauth Middleware (500/min per IP) │
│ └─ Blocks random auth_flow_id hammering before DB access │
│ │
│ 2. Config/OAuth Rate Limits (token bucket) │
│ └─ Burst-friendly for enterprise login spikes │
│ │
│ 3. Verification Rate Limits (layered) │
│ ├─ Temporary lockout (10 failures → 30 min lock) │
│ ├─ Exponential backoff (3+ failures → increasing delays) │
│ ├─ Per-env per-email limit │
│ ├─ Per-env per-IP limit │
│ └─ Global email safety net │
│ │
│ 4. Email Rate Limits │
│ ├─ Deduplication (3 min window) │
│ ├─ Per-env per-email hourly │
│ ├─ Per-env per-IP hourly │
│ └─ Global daily safety net │
└─────────────────────────────────────────────────────────────────┘
TierMultiplierUse Case
DEFAULT1xStandard limits for most customers
ENTERPRISE5xHigher limits for enterprise customers
CUSTOMConfigurablePer-limit overrides via rate_limit_overrides

Applied before any database access to block attackers hammering random auth flow IDs.

LimitScopePurpose
500/minPer IPHigh threshold to block automated attacks
LimitScopePurpose
120/minPer IP (token bucket)Burst-friendly for enterprise SSO
600/minPer environmentCircuit breaker per tenant

Credential Verification (Layered Protection)

Section titled “Credential Verification (Layered Protection)”
LayerLimitScopeTrigger
Temporary lockout30 min lockPer env + email10+ failures
Exponential backoff5s → 15 minPer env + email3+ failures
Rate limit5/15minPer env + emailStandard limit
Rate limit10/15minPer env + IPStandard limit
Global safety net20/15minGlobal per emailPrevents tenant rotation
LayerLimitScope
Deduplication3 min windowPer env + email + type
Hourly per address3/hourPer env + email + type
Hourly per IP10/hourPer env + IP + type
Daily global20/dayGlobal per email

All rate limits are configurable via environment variables.

VariableDefaultDescription
RATE_LIMIT_CONFIG_PER_IP120/minuteConfig endpoint per IP
RATE_LIMIT_CONFIG_PER_ENV600/minuteConfig endpoint per environment
RATE_LIMIT_VERIFY_PER_ENV_EMAIL5/15minutesPer env + email
RATE_LIMIT_VERIFY_PER_ENV_IP10/15minutesPer env + IP
RATE_LIMIT_EMAIL_PER_ENV_ADDR3/hourPer env + email + type
RATE_LIMIT_EMAIL_GLOBAL_DAILY20/dayGlobal daily per email
BACKOFF_BASE_SECONDS5Initial backoff delay
BACKOFF_MAX_SECONDS900Maximum backoff (15 min)
BACKOFF_LOCKOUT_THRESHOLD10Failures before lockout
RATE_LIMIT_ENTERPRISE_MULTIPLIER5.0Multiplier for enterprise tier
HTTP/1.1 429 Too Many Requests
Retry-After: 847
{
"detail": "Too many verification attempts. Please try again later.",
"code": "rate_limit_exceeded"
}
HTTP/1.1 429 Too Many Requests
Retry-After: 1800
{
"detail": "Account temporarily locked due to too many failed attempts.",
"code": "exceeded_max_login_attempts"
}

The Retry-After header indicates seconds until the limit resets.