Skip to content

fix: apply rate limiting to all routes, not just POST /payments - #202

Merged
Manuel1234477 merged 2 commits into
StellarGateLabs:mainfrom
Me7858:closes-72
Jul 25, 2026
Merged

fix: apply rate limiting to all routes, not just POST /payments#202
Manuel1234477 merged 2 commits into
StellarGateLabs:mainfrom
Me7858:closes-72

Conversation

@Me7858

@Me7858 Me7858 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #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 any restriction, enabling DoS and payment enumeration abuse.

Changes

src/api/mod.rs only — no new dependencies, no config 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 a "default" bucket.
  • New bucket_rate_multiplier function calibrates each bucket from the same RATE_LIMIT_REQUESTS_PER_SEC env variable:

    • Named write buckets: base rate × 1 (unchanged behaviour — POST /payments still 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_middleware passes the effective rate (base × multiplier) when creating per-key limiters, so each bucket is independently calibrated.

Acceptance criteria

  • All routes have a default limit.
  • Sensitive routes (POST /payments, POST /merchants, redelivery) have stricter per-bucket limits.

Testing

  • cargo check --lib passes cleanly (no new dependencies introduced).
  • The only compile error in the repo (crate::TaskHealth in main.rs) is pre-existing and unrelated to this change.

Me7858 and others added 2 commits July 23, 2026 14:41
…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
@Manuel1234477
Manuel1234477 merged commit 36011df into StellarGateLabs:main Jul 25, 2026
1 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rate limiting only covers POST /payments; other endpoints are unthrottled

2 participants