Skip to content

feat: add Redis leaky bucket rate limiter with Sybil analysis flagging#95

Merged
elizabetheonoja-art merged 3 commits intoSubStream-Protocol:mainfrom
GazzyLee:feat/redis-leaky-bucket-rate-limiter
Mar 25, 2026
Merged

feat: add Redis leaky bucket rate limiter with Sybil analysis flagging#95
elizabetheonoja-art merged 3 commits intoSubStream-Protocol:mainfrom
GazzyLee:feat/redis-leaky-bucket-rate-limiter

Conversation

@GazzyLee
Copy link
Copy Markdown
Contributor

feat: Redis Leaky Bucket Rate Limiter with Sybil Analysis

Adds per-wallet rate limiting using a Redis-backed Leaky Bucket algorithm to protect /api endpoints from scraping and bot abuse.

Changes

  • Leaky Bucket rate limiter (leakyBucketRateLimiter.js) — Atomic Redis Lua script enforcing configurable token capacity per wallet. Temporarily blocks offenders (default 5 min).
  • Sybil Analysis flagging (sybilAnalysisService.js) — Wallets exceeding a violation threshold are flagged in a ranked sorted set with metadata (IP, endpoint, timestamp) for admin review.
  • Express middleware (rateLimiter.js) — Extracts wallet from auth context, enforces limits, returns 429 + Retry-After headers. Fails open on Redis errors.
  • Redis client (redis.js) — Singleton ioredis client with retry strategy and graceful shutdown.
  • Tests (rateLimiter.test.js) — Full coverage of bucket logic, blocking, Sybil flagging, middleware integration, and Redis failure handling (mocked).

Config (env vars)

REDIS_URL, RATE_LIMIT_CAPACITY (60), RATE_LIMIT_LEAK_RATE (1/s), RATE_LIMIT_BLOCK_SECONDS (300), SYBIL_THRESHOLD (3)

Closes #53

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 25, 2026

@GazzyLee Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@elizabetheonoja-art elizabetheonoja-art merged commit b4e60be into SubStream-Protocol:main Mar 25, 2026
1 check failed
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.

#18 Implement Bot_Detection_and_Rate_Limiting for API

3 participants