Skip to main content

Rate Limiting

IDP implements rate limiting to prevent abuse and protect against brute-force attacks.

Refresh Endpoint Rate Limiting

The /auth/refresh endpoint has per-IP and per-JTI (session) rate limits to prevent refresh storms.

LimitDefaultEnv VariableDescription
Per-IP120 req/minIDP_REFRESH_RATE_LIMIT_IPLimits requests from a single IP address
Per-JTI30 req/minIDP_REFRESH_RATE_LIMIT_JTILimits requests for a single session

Response

When rate limit is exceeded:

  • Returns 429 Too Many Requests
  • Includes Retry-After header (seconds until reset)
  • Logs warning with request metadata

Implementation

ComponentDescription
PrimaryRedis-backed via @nestjs-modules/ioredis
FallbackIn-memory Map when Redis unavailable
GuardRefreshRateLimitGuard in apps/idp/src/app/guards/

Configuration

# Rate limits (format: Xr/Ys where X=requests, Y=seconds)
IDP_REFRESH_RATE_LIMIT_IP=120r/60s # 120 requests per minute per IP
IDP_REFRESH_RATE_LIMIT_JTI=30r/60s # 30 requests per minute per session

Account Lifecycle Rate Limits

EndpointLimitScope
POST /auth/account/delete-request3/5minPer-user (JWT)
DELETE /auth/account5/5minPer-user (JWT)
POST /auth/account/restore-request3/5minPer-IP
POST /auth/account/restore5/5minPer-IP
GET /auth/account/export5/hourPer-user (JWT)

Password Reset Rate Limits

Password reset endpoints implement enumeration-resistant rate limiting:

EndpointLimitNotes
POST /auth/forgot-password5/min per-IPAlways returns 204
POST /auth/reset-password5/min per-IPToken validation

OTP Rate Limits

OTP verification has brute-force protection:

  • 5 failed attempts triggers 15-minute lockout
  • Progressive backoff on repeated failures

Monitoring

Check rate limit hits in logs:

kubectl logs -n idp deployment/idp-backend | grep -i "rate limit"

Prometheus metrics (when enabled):

  • idp_rate_limit_exceeded_total{endpoint, scope}