Skip to content

[FEAT] Security/Reliability: Global Rate-Limiting Edge Middleware & Circuit BreakerΒ #701

Description

@Diwakar-odds

✨ Feature Description

Create a robust Edge middleware utilizing a Token Bucket rate-limiting algorithm and a Circuit Breaker pattern for external dependencies.

πŸ€” Problem It Solves

The application lacks global protection against distributed brute-force attacks on NextAuth login endpoints and malicious link spamming on the api/links API. Standard Next.js route handlers are exposed to DDOS attacks. Additionally, third-party API dependencies (OAuth providers, DB) have no fault tolerance when they experience downtime.

πŸ’‘ Proposed Solution

  1. Build lib/rate-limit.ts using Redis to track IP requests and enforce limits (e.g., 5 login attempts per 15 mins, 30 API calls per minute).
  2. Integrate this into middleware.ts to block requests at the edge before they hit serverless functions.
  3. Implement a Circuit Breaker pattern (lib/circuit-breaker.ts) for external OAuth providers and DB connections to fail fast (returning 503 Service Unavailable) instead of hanging indefinitely during third-party outages.

πŸ”„ Alternatives Considered

Using standard Vercel WAF limits is an option, but application-level Edge middleware allows us to return customized JSON responses, track limit hits in our DB, and dynamically adjust limits based on route importance.

πŸ—‚οΈ Files Likely Involved

  • app/api/ β€” API routes
  • Other: middleware.ts, lib/rate-limit.ts, lib/circuit-breaker.ts

πŸ“Έ Mockup / Reference

N/A

🎯 Acceptance Criteria

  • IP-based rate limiting functions correctly in middleware.ts.
  • Exceeding limits returns a 429 Too Many Requests response.
  • Circuit breaker wraps external API calls and returns 503 upon failure threshold.

🏷️ Difficulty & Labels

  • good first issue β€” beginner friendly
  • medium β€” requires some codebase knowledge
  • hard β€” significant changes needed
  • nsoc-26 β€” open for NSoC contributors

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions