Skip to content

fix(server): add per-IP rate limit on /health endpoint (NET-002) - #230

Merged
imran-siddique merged 1 commit into
mainfrom
fix/net-002-health-rate-limit
Jun 7, 2026
Merged

fix(server): add per-IP rate limit on /health endpoint (NET-002)#230
imran-siddique merged 1 commit into
mainfrom
fix/net-002-health-rate-limit

Conversation

@imran-siddique

Copy link
Copy Markdown
Member

Summary

  • Adds _RateLimitMiddleware: sliding-window counter (60 requests/minute per source IP) applied to all paths in _AUTH_EXEMPT_PATHS (currently /health)
  • Returns 429 with Retry-After: 60 header when exceeded, body {"error": "Too Many Requests", "error_code": "RATE_LIMITED"}
  • Rate limiter runs before auth middleware so unauthenticated probes are bounded before they touch any auth logic
  • All state is in-process (no Redis dependency) — appropriate for a single-gateway deployment

Test plan

  • pytest tests/unit/test_mcp_server_auth.py -v — 18 passed (3 new tests)
  • pytest tests/unit/ -q — 396 passed

Closes #178

🤖 Generated with Claude Code

Adds _RateLimitMiddleware (sliding-window, 60 req/min per IP) that wraps
the unauthenticated /health path before auth middleware runs. Returns 429
with Retry-After: 60 when the limit is exceeded. Falls back gracefully
when client IP is unavailable.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@imran-siddique
imran-siddique merged commit 8dd5988 into main Jun 7, 2026
1 of 8 checks passed
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.

MEDIUM: No rate limiting on unauthenticated /health and /metrics endpoints (NET-002)

1 participant