fix: apply rate limiting to all routes, not just POST /payments - #202
Merged
Conversation
…larGateLabs#72) Previously rate_limited_bucket returned None for every non-POST request, leaving GET /payments (list), GET /payments/:id, GET /payments/:id/webhooks, GET /health, GET /ready, GET /metrics, and any unknown POST route completely unprotected — they could be flooded without restriction. Changes: - rate_limited_bucket now returns Some for every request. - Write/sensitive POSTs keep their named buckets: "payments", "merchants", "redeliver". - Everything else (all GETs, unknown POSTs) falls into the "default" bucket. - Add bucket_rate_multiplier to give read-only traffic a more generous allowance without changing the base configuration: - Named write buckets: base rate × 1 (unchanged behaviour) - "default" bucket: base rate × 5 (e.g. 50 req/s when RATE_LIMIT_REQUESTS_PER_SEC=10) - rate_limit_middleware passes the effective rate (base × multiplier) when creating per-key limiters, so each bucket is independently calibrated from the same env variable. Acceptance criteria: - All routes now have a default limit. - Sensitive write routes retain stricter per-bucket limits. Closes StellarGateLabs#72
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
Fixes #72.
Previously
rate_limited_bucketreturnedNonefor every non-POST request, leavingGET /payments(list),GET /payments/:id,GET /payments/:id/webhooks,GET /health,GET /ready,GET /metrics, and any unknown POST route completely unprotected — they could be flooded without any restriction, enabling DoS and payment enumeration abuse.Changes
src/api/mod.rsonly — no new dependencies, no config changes.rate_limited_bucketnow returnsSomefor every request:"payments","merchants","redeliver"."default"bucket.New
bucket_rate_multiplierfunction calibrates each bucket from the sameRATE_LIMIT_REQUESTS_PER_SECenv variable:POST /paymentsstill gets 10 req/s at default config)."default"bucket: base rate × 5 (e.g. 50 req/s at default config) — generous enough for normal polling without leaving reads unguarded.rate_limit_middlewarepasses the effective rate (base × multiplier) when creating per-key limiters, so each bucket is independently calibrated.Acceptance criteria
POST /payments,POST /merchants, redelivery) have stricter per-bucket limits.Testing
cargo check --libpasses cleanly (no new dependencies introduced).crate::TaskHealthinmain.rs) is pre-existing and unrelated to this change.