Skip to content

[marvis-misakaAron] Three-tier rate limiting with JWT auth differentiation (#200)#4892

Closed
misakaAron wants to merge 1 commit into
ClankerNation:mainfrom
misakaAron:fix/ratelimit-tiered-auth
Closed

[marvis-misakaAron] Three-tier rate limiting with JWT auth differentiation (#200)#4892
misakaAron wants to merge 1 commit into
ClankerNation:mainfrom
misakaAron:fix/ratelimit-tiered-auth

Conversation

@misakaAron
Copy link
Copy Markdown

Summary

Three-tier rate limiting middleware that differentiates anonymous, authenticated, and premium users via JWT-based auth detection.

Changes (api/middleware/ratelimit.py)

Three-tier limits (sliding window):

Tier Limit Window
Anonymous 60 req/min 60s
Authenticated 300 req/min 60s
Premium 1000 req/min 60s

Key design:

  • Sliding window per-client-key (replaces buggy fixed-window)
  • Tier determined from JWT Authorization header: valid token = authenticated, premium role = premium
  • Expired/invalid/missing tokens fall back to anonymous
  • X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset on every response
  • 429 includes Retry-After header
  • Health endpoint exempted

Tests (test/test_ratelimit.py)

17 tests: each tier within/exceeds limit, correct headers per tier, 429 Retry-After, health bypass, separate counters, invalid token falls to anonymous.

Fixes #200

收款Payoneer: 790637254@qq.com

@github-actions
Copy link
Copy Markdown

Unfortunately the changes in this PR didn't fully resolve the issue. Please rework your solution and submit a new pull request within 2 hours.

Make sure to review the acceptance criteria in the linked issue and verify all conditions are met before resubmitting.

@github-actions github-actions Bot closed this May 29, 2026
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.

[ Bounty $2k ] [ API ] Fix ratelimit.py doesn't differentiate authenticated vs anonymous limits — backwards compat

1 participant