Skip to content

fix: enforce per-token rate limiting for authenticated API users#154

Open
malteos wants to merge 6 commits intomasterfrom
fix/api-user-rate-limiting
Open

fix: enforce per-token rate limiting for authenticated API users#154
malteos wants to merge 6 commits intomasterfrom
fix/api-user-rate-limiting

Conversation

@malteos
Copy link
Contributor

@malteos malteos commented Feb 25, 2026

Summary

  • Add TokenUserRateThrottle to DEFAULT_THROTTLE_CLASSES so the existing "user": "5000/hour" rate is actually enforced for authenticated users (previously only AnonRateThrottle was active)
  • Add rate_limit field to APIToken model allowing per-token rate override (NULL = use default)
  • Add admin UI support for viewing/filtering/editing the rate limit field

Test plan

  • 8 new throttle tests (test_throttling.py): basic throttling, anonymous bypass, custom rate override (higher/lower), session auth, Retry-After header, per-user counters, rate_limit=0
  • 2 new model tests for rate_limit field default and custom value
  • Full test suite passes (12 pre-existing ES connection errors unrelated)
  • ruff format and ruff check clean

🤖 Generated with Claude Code

malteos and others added 6 commits February 23, 2026 16:57
… pagination

Homepage no longer runs COUNT(*) for cases/laws — button now says
"View all cases" instead of showing the exact total. Case list pagination
uses LimitedPaginator and shows "> N items" when the count exceeds
PAGINATE_BY * PAGINATE_UNTIL.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Also updates the DE theme homepage to remove explicit counts from both
the cases and laws buttons.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add dedicated docs/sitemap-xml.md covering sitemap feature (URLs, caching,
sections, how to extend). Add Sitemap directive to robots.txt so search
engines can discover the sitemap index automatically.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The DEFAULT_THROTTLE_CLASSES only contained AnonRateThrottle, so the
"user": "5000/hour" rate in DEFAULT_THROTTLE_RATES was dead config.
Add a custom TokenUserRateThrottle that enforces the default rate for
all authenticated users and supports per-token overrides via a new
rate_limit field on APIToken.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant