mirror of https://github.com/interlegis/sapl.git
Browse Source
django-ratelimit (the @ratelimit view decorator) writes its counters through Django's cache framework. Django's default key function produces '{KEY_PREFIX}:{VERSION}:{key}', so with KEY_PREFIX='' and VERSION=1 (defaults) the decorator keys appear in Redis as ':1:rl:{hash}' — an ugly leading colon that makes them look distinct from the clean 'rl:*' keys written by RateLimitMiddleware via get_redis_connection(). Add make_ratelimit_cache_key() to sapl/middleware/ratelimit.py (a simple pass-through) and wire it into the 'ratelimit' cache config via KEY_FUNCTION. Both key families now share the same 'rl:*' namespace: decorator keys → rl:{hash} middleware keys → rl:ip:{ip}:reqs rl:{ns}:user:{uid}:reqs rl:{ns}:ip:{ip}:w:{bucket} Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>rate-limiter-2026
2 changed files with 22 additions and 1 deletions
Loading…
Reference in new issue