chores: add rate_limiting - #109
Merged
Merged
Conversation
|
@KodeSage Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
codebestia
approved these changes
Jun 2, 2026
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.
Description
CLOSE #9
Adds per-IP rate limiting to the unauthenticated auth endpoints to prevent abuse — both endpoints were previously unprotected and could be spammed indefinitely, generating nonces and burning CPU on Stellar signature verification.
Uses
express-rate-limitwith per-route middleware (not router-level), so authenticated routes are unaffected:POST /auth/challenge— 10 requests / minute / IPPOST /auth/verify— 5 requests / minute / IP (lower because it runs SHA-256 + Stellar Ed25519 verification + a DB upsert)Exceeding either limit returns
429 Too Many Requestswith aRetry-Afterheader (viastandardHeaders: 'draft-7').Files changed
apps/backend/src/routes/auth.ts— definedchallengeLimiterandverifyLimiter, wired each in front of its respective route'svalidate(...)middleware.apps/backend/src/__tests__/auth.integration.test.ts— addedresetRateLimiters()helper into existingbeforeEachs (so the new middleware doesn't bleed across the existing 10 tests), plus a newdescribe('Auth rate limiting')block with 5 tests.apps/backend/package.json— addedexpress-rate-limit@^8.5.2.Acceptance criteria
Retry-Afterheader is present on 429 responses.Follow-ups (not in this PR)
MemoryStorefor a Redis-backed store (e.g.rate-limit-redis) using the existing client inapps/backend/src/lib/redis.tswhen the backend is scaled horizontally.app.set('trust proxy', ...)soreq.ipis the real client IP.Type of change
Checklist
Test run:
New test cases:
/auth/challengerequests succeed; 11th returns 429 withRetry-After./auth/verifyrequests succeed; 6th returns 429 withRetry-After./auth/verifydoes not block/auth/challenge./me(authenticated) is unaffected — 20 consecutive requests never return 429./healthis unaffected — 20 consecutive requests never return 429.