]> git.ipfire.org Git - dbl.git/commitdiff
ratelimiter: Change limit for the entire class after auth
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 3 Mar 2026 16:56:36 +0000 (16:56 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 3 Mar 2026 16:56:36 +0000 (16:56 +0000)
We are accessing the limit variables outside of this function, so we
will have to reset limit. This is slightly annoying, but we cannot
perform any authentication checks in __init__().

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/dbl/ratelimiter.py

index 920156132f8b8ff8056664fffb8725b4c354bf14..173aac0a5b61cd6f6dad90594428bc17a1119c69 100644 (file)
@@ -132,8 +132,6 @@ class RateLimiterRequest(object):
                """
                        Returns True if the request is prohibited by the rate limiter
                """
-               limit = self.limit
-
                # Fetch the API key
                if self.api_key:
                        # Fetch the API key
@@ -148,16 +146,13 @@ class RateLimiterRequest(object):
                                # If authenticated users have a different limit set,
                                # we change the checked limit to that
                                if self.auth_limit:
-                                       limit = self.auth_limit
+                                       self.limit = self.auth_limit
 
                # Fetch the number of past requests
                self.requests = await self.get_requests()
 
-               # Assert that some limit has been set
-               assert limit
-
                # The client is rate-limited when more requests have been received than allowed
-               if self.requests >= limit:
+               if self.requests >= self.limit:
                        return True
 
                # Increment the request counter