DevByte-Community / DevByte-Community/Community-API-Backend

Implement Rate Limiting for Critical Endpoints

Abierto
#73 0 comentarios 0 reacciones 0 asignados Ver en GitHub
security
Lenguaje dominante
JavaScript
Estrellas
2
Forks
11
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Ticket ID: SEC-RATELIMIT-001
Priority: High
Security Level: CRITICAL

**Feature Description**

Implement rate limiting on critical API endpoints to prevent abuse, brute force attacks, and ensure fair usage of platform resources. Protect authentication, registration, and data-intensive endpoints.

**Acceptance Criteria**

1. Protected Endpoints ✅

- High Priority (Strict Limits):

- POST /api/auth/login - 5 attempts per 15 minutes per IP

- POST /api/auth/register - 3 attempts per hour per IP

- POST /api/auth/forgot-password - 3 attempts per hour per IP

- POST /api/auth/reset-password - 5 attempts per hour per IP

- Medium Priority (Standard Limits):

- GET /api/metrics/dashboard - 30 requests per minute per user

- POST /api/projects - 10 creations per 30 minutes per user

- POST /api/events - 10 creations per 30 minutes per user

- POST /api/blogs - 5 creations per 30 minutes per user

- General Protection:

- All other authenticated endpoints: 100 requests per minute per user

- All public endpoints: 60 requests per minute per IP

2. Implementation Requirements ✅

- Use express-rate-limit middleware or another

- Redis store for distributed rate limiting (production)

- Memory store for testing

- Clear, consistent HTTP headers:
```
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1633039200
Retry-After: 60 (when blocked)
```

3. Response Format ✅
```
json

{
"error": "Too Many Requests",
"message": "Rate limit exceeded. Please try again in 60 seconds.",
"retryAfter": 60,
"timestamp": "2024-01-15T10:30:00Z"
}
```

`Status Code: 429 Too Many Requests`

4. Configuration ✅

Environment-based configuration:
```
env

RATE_LIMIT_ENABLED=true
RATE_LIMIT_WINDOW_MS=60000
RATE_LIMIT_MAX_REQUESTS=100
```

- Different limits for development/production

- Ability to disable for specific routes (webhooks, health checks)

5. Skip List ✅

- Exclude from rate limiting:

- GET /api/health - Health checks

- GET /api/docs - API documentation

- Internal webhook endpoints (specify which)

6. Monitoring & Logging ✅

- Log rate limit hits with context (user, endpoint, IP)

- Send alert on sustained rate limit violations (>10 blocks in 5min)

- Metrics exposed: rate_limit_hits_total, rate_limit_blocks_total

- Admin endpoint to view current rate limit status: GET /api/admin/rate-limits/status

8. Documentation ✅

- Create a security docs folder and draft a detailed rate_limit.md file explaining the overall strategy

9. Testing ✅

- Unit tests for rate limit middleware

- Integration tests verifying limits work correctly

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.