Skip to content

Configure Route-Level Rate Limiting for Auth and Settlement Endpoints #285

Description

@Cjay-Cyber-2

Description

To protect against authentication brute-force attacks and automated settlement spam, dedicated rate limits need to be applied to sensitive authentication and transaction submission routes using @fastify/rate-limit.

Context & Requirements

  • Fastify rate limit plugin (@fastify/rate-limit) is installed in dependencies.
  • Global defaults should remain, but strict rate limits must be configured for high-risk endpoints:
    • SEP-10 challenge generation (POST /auth/challenge): max 10 requests per minute per IP.
    • SEP-10 token exchange (POST /auth/token): max 10 requests per minute per IP.
    • Settlement transaction submission (POST /settlements/submit): max 20 requests per minute per user/IP.

Acceptance Criteria

  • Configure custom config.rateLimit route options on target endpoint handlers in src/routes/auth.ts and src/routes/settlements.ts.
  • Ensure rate limit headers (x-ratelimit-limit, x-ratelimit-remaining, x-ratelimit-reset) are returned in HTTP responses.
  • Return standard Fastify 429 Too Many Requests response payload on threshold breach.
  • Ensure rate limits do not impact internal service calls or integration test runs.
  • Write integration test validating 429 status code response upon exceeding limit.

Implementation Guidance

  • Register and configure route-specific limits using Fastify plugin route config objects.
  • Keep rate limit definitions clear and configurable via environment settings if applicable.
  • Ensure test suite disables or handles rate limiters properly during integration test execution.

Testing & Validation

  • Run npm test and npm run test:integration to ensure standard tests pass.
  • Add an integration test in tests/rateLimit.test.ts firing rapid requests to verify 429 response behavior.

Submission Guidelines

  • Open a PR that includes "Closes #".
  • Ensure task assignment before work commences.
  • Run npm run lint before submitting.

Wave complexity: Medium

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions