Skip to content

Return RFC 6585 429 responses with Retry-After from rateLimit middleware #259

@mikewheeleer

Description

@mikewheeleer

Description

When request limits are exceeded the API should return a standards-compliant 429 with a Retry-After header rather than a generic error. Align the rateLimit middleware with the safe-error policy in src/errors/errorMessagePolicy.

Requirements and context

  • Emit 429 Too Many Requests with Retry-After and X-RateLimit-* headers reflecting remaining budget.
  • Use src/errors/safeErrors.ts so no internal limiter state leaks to clients.
  • Document headers and client backoff guidance in docs/request-limits-implementation.md.
  • Acceptance: integration test asserts header values and that the body matches the safe-error contract.

Suggested execution

  • Fork the repo and create a branch:
    • git checkout -b enhancement/rate-limit-429-headers
  • Implement changes:
    • src/rateLimit.ts
    • Tests: src/rateLimit.integration.test.ts
    • Docs: docs/request-limits-implementation.md
    • Include TSDoc/NatSpec-style doc comments
    • Validate security assumptions (input validation, auth, signature verification, secret redaction, idempotency)

Test and commit

  • Run tests: npm test (coverage: npm run test:ci)
  • Cover edge cases
  • Include test output and security notes in the PR

Example commit message

feat(rate-limit): return 429 with Retry-After headers

Guidelines

  • Minimum 95% line coverage on new/changed code
  • No secrets in repo; use .env + deployment secrets only
  • Clear documentation
  • Timeframe: 96 hours from assignment

Metadata

Metadata

Assignees

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions