β¨ 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
- 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).
- Integrate this into
middleware.ts to block requests at the edge before they hit serverless functions.
- 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
πΈ Mockup / Reference
N/A
π― Acceptance Criteria
π·οΈ Difficulty & Labels
β¨ 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/linksAPI. 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
lib/rate-limit.tsusing Redis to track IP requests and enforce limits (e.g., 5 login attempts per 15 mins, 30 API calls per minute).middleware.tsto block requests at the edge before they hit serverless functions.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 routesmiddleware.ts,lib/rate-limit.ts,lib/circuit-breaker.tsπΈ Mockup / Reference
N/A
π― Acceptance Criteria
middleware.ts.π·οΈ Difficulty & Labels
good first issueβ beginner friendlymediumβ requires some codebase knowledgehardβ significant changes needednsoc-26β open for NSoC contributors