Repository navigation
feat(auth): add rate limiting for sensitive endpoints using Durable Object or KV - #136
Open
Lakshya-2440 wants to merge 1 commit into
Open
Lakshya-2440 wants to merge 1 commit into
Lakshya-2440 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses Issue 4 (Tier 1 Core Architecture, Edge Security & Cryptography):
feat(auth): add rate limiting for sensitive endpoints using Durable Object or KV.Currently, in-memory rate limiting (
_AUTH_RATE_LIMIT_STATE) is isolate-local and resets whenever Cloudflare recycles the Worker isolate. This change introduces persistent, sliding-window rate limiting backed by a Durable Object actor (RateLimiterDO), with KV storage support and in-memory fallback.Key Changes
RateLimiterDOActor (src/worker.py):DurableObjectactor tracking sliding-window attempt timestamps.Retry-Afterheader values based on the oldest attempt falling outside the window.check_limit) and HTTP requests (on_fetch/fetch).PresenceDOif used as the DO binding.wrangler.toml:RATE_LIMITER_DObinding (class_name = "RateLimiterDO").v3migration withnew_sqlite_classes = ["RateLimiterDO"].src/worker.py):RATE_LIMITER_DO->RATE_LIMIT_KV-> in-memory bounded sliding window./api/login,/api/register,/api/forgot-password,/api/profile/password, and/api/confirm-password-change.CF-Connecting-IP) to block volumetric burst attacks.username_hash/email_hash) to prevent distributed credential-stuffing across rotated IPs.Retry-Afterheader when attempts exceed 5 attempts/failures per minute.tests/test_dispatcher.py):TestAuthRateLimitingwith comprehensive end-to-end routing tests:RateLimiterDOactor.RATE_LIMIT_KVstore.CF-Connecting-IPguard check.Verification
pytest tests/test_dispatcher.pypasses 100% (43 passed).pytest tests/test_api_auth.pypasses 100% (21 passed).