fix: Security: Implement Rate Limiting for Payment Endpoints#261
Open
Kaycee276 wants to merge 3 commits into
Open
fix: Security: Implement Rate Limiting for Payment Endpoints#261Kaycee276 wants to merge 3 commits into
Kaycee276 wants to merge 3 commits into
Conversation
…r Payment Endpoints
Collaborator
|
@Kaycee276 PLEASE RESOLVE CONFLICTS |
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
Added slowapi-based rate limiting for payment endpoints.
app/core/rate_limit.pymodule centralising theLimiterinstance. It keys by authenticated user id (falling back to Authorization header or client IP) and exposes configurable limit strings via environment variables (RATE_LIMIT_PAYMENT_PREPARE,RATE_LIMIT_PAYMENT_SUBMIT,RATE_LIMIT_PAYMENT_SUBMIT_FAILED,RATE_LIMIT_PAYMENT_RELEASE,RATE_LIMIT_PAYMENT_REFUND) with sensible defaults (10/min for prepare/release/refund, 5/min for submit, 3/min for failed submits).app/main.py: registered onapp.state, added theSlowAPIMiddleware, and installed theRateLimitExceededexception handler so clients get a proper429response./prepare,/submit,/release, and/refundinapp/api/v1/endpoints/payments.pywith@limiter.limit(...). Added a stricter secondary bucket for/submitthat only consumes quota when a submission fails (invalid XDR, unknown booking, unauthorized caller, or backend error), and_check_failed_submit_quotarejects further submissions with a429once that bucket is exhausted — bluntingbooking_idbrute-force and Stellar-network spam attempts without penalising legitimate users.slowapi==0.1.9tobackend/requirements.txt.closes #199