Skip to content

feat: IP-based rate limiting for login endpoint#585

Merged
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
ayomidearegbeshola29-dev:task/login-throttle
Jun 29, 2026
Merged

feat: IP-based rate limiting for login endpoint#585
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
ayomidearegbeshola29-dev:task/login-throttle

Conversation

@ayomidearegbeshola29-dev

Copy link
Copy Markdown
Contributor

Login IP Throttle

Feature Description

This implementation adds IP-based rate limiting for login attempts on the /auth/wallet endpoint. Each IP address is limited to a configurable number of login attempts within a sliding time window to prevent brute force attacks.

API Changes

Login Endpoint

POST /auth/wallet

The wallet login endpoint is now protected by IP-based rate limiting:

  • Default: 5 requests per 60 seconds per IP address
  • Rate limit headers: Returns Retry-After header when throttled
  • Response on throttling:
{
  "code": "TOO_MANY_REQUESTS",
  "message": "Too Many Requests",
  "requestId": "req-xxx",
  "retryAfterMs": 30000
}

Configuration

Environment variables (with defaults):

Variable Default Description
LOGIN_RATE_LIMIT_MAX_REQUESTS 5 Maximum login attempts per window
LOGIN_RATE_LIMIT_WINDOW_MS 60000 Window size in milliseconds (1 minute)
TRUST_PROXY_HEADERS false Enable proxy header support for accurate IP detection

Behavior

Sliding Window

The rate limiter uses a sliding window approach. Each successful request increments a counter that expires after the configured window. When the counter reaches the limit, subsequent requests are rejected with 429.

IP Detection

  • By default (no proxy), uses the direct socket connection IP
  • When TRUST_PROXY_HEADERS=true, respects standard proxy headers (X-Forwarded-For, X-Real-IP, etc.) for accurate client IP detection behind load balancers

Per-IP Isolation

Rate limits are tracked independently per IP address. Multiple attackers from different IPs each get their own budget.

Security Considerations

  • Rate limiting prevents credential stuffing and brute force attacks
  • Response uses standardized error envelope (code, message, requestId)
  • No IP addresses are exposed in error responses
  • Structured logging includes client IP for monitoring and alerting
  • Uses existing getClientIp utility for consistent IP extraction across the codebase

Test Coverage

  • Unit tests for InMemoryLoginRateLimiter covering all edge cases
  • Unit tests for createLoginThrottle middleware
  • Tests for window expiry behavior
  • Tests for per-IP isolation
  • Tests for Retry-After header consistency

closes #516

- Create loginThrottle middleware for /auth/wallet endpoint
- Add environment configuration (LOGIN_RATE_LIMIT_MAX_REQUESTS, LOGIN_RATE_LIMIT_WINDOW_MS)
- Apply sliding window rate limit per IP address
- Support proxy headers for accurate IP detection when TRUST_PROXY_HEADERS=true
- Return 429 with Retry-After header when limit exceeded
- Use standardized error envelope (code, message, requestId)
- Add comprehensive unit tests for middleware and limiter class
@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@ayomidearegbeshola29-dev Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@greatest0fallt1me greatest0fallt1me merged commit 05faa6c into CalloraOrg:main Jun 29, 2026
@grantfox-oss grantfox-oss Bot mentioned this pull request Jun 29, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add IP throttle on /api/auth/login

2 participants