Skip to content

feat: add Redis-backed API rate limits#62

Open
snkk2x-collab wants to merge 2 commits into
Zcorehub:mainfrom
snkk2x-collab:codex/redis-rate-limit-42
Open

feat: add Redis-backed API rate limits#62
snkk2x-collab wants to merge 2 commits into
Zcorehub:mainfrom
snkk2x-collab:codex/redis-rate-limit-42

Conversation

@snkk2x-collab

Copy link
Copy Markdown

Summary

Implements Redis-backed public API rate limiting for #42 using Upstash Redis REST without adding a production SDK dependency.

Changes

  • Added a reusable rate-limit.middleware.ts with route-specific limits:
    • POST /api/auth/challenge: 10/min per IP
    • POST /api/auth/*/signed: 5/min per IP
    • POST /api/events/report: 100/min per API key
    • GET /api/user/{wallet}/score: 60/min per lender API key
  • Returns HTTP 429 with Retry-After and readable JSON when the limit is exceeded.
  • Fails open with a warning if Upstash is not configured or temporarily unavailable.
  • Added Vitest coverage for allow-without-Redis, 429 responses, and Redis failure fallback.
  • Documented UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN in .env.example and README.

Validation

  • pnpm --dir Server exec vitest run src/middleware/__tests__/rate-limit.middleware.test.ts
  • pnpm --dir Server exec vitest run
  • pnpm --dir Server exec tsc --noEmit --declaration false

Closes #42

@snkk2x-collab snkk2x-collab force-pushed the codex/redis-rate-limit-42 branch from e4b4e68 to e9eb058 Compare June 19, 2026 23:06
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.

Redis-backed rate limiting on public API endpoints

1 participant