Skip to content

Add rate limit response headers (X-RateLimit-*) #423

Description

@Wilfred007

What

Add standard rate limit headers (X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, Retry-After) to all API responses. The backend has a comprehensive rate limiting system (tiered, smart, organization-based) but clients currently have no way to know their rate limit status without hitting a 429.

Why

Without rate limit headers, frontend developers and API consumers can't implement proactive throttling. They only discover limits after being rejected with a 429, which causes UX disruptions. Standard headers let clients display "slow down" messaging and implement exponential backoff correctly.

Scope

In scope:

  • Add a middleware that appends rate limit headers to every API response
  • Headers: X-RateLimit-Limit (total allowed), X-RateLimit-Remaining (remaining), X-RateLimit-Reset (UTC epoch when limit resets), Retry-After (seconds, only on 429 responses)
  • Integrate with the existing smartRateLimiter and organizationRateLimiter middleware
  • Support per-route overrides (e.g., auth endpoints may have lower limits)

Out of scope:

Acceptance Criteria

  • All API responses include X-RateLimit-Limit and X-RateLimit-Remaining headers
  • X-RateLimit-Reset is included as a UTC epoch timestamp
  • 429 responses include Retry-After header with seconds until reset
  • Headers reflect the actual limits from the smart/organization rate limiters
  • Headers are present in both success and error responses
  • No performance regression from header generation

Technical Context

  • Rate limiters: backend/src/middleware/smartRateLimiter.ts, organizationRateLimiter.ts
  • Throttling: backend/src/middleware/throttlingMiddleware.ts
  • App middleware stack: backend/src/app.ts
  • Tenant rate limiting: backend/src/services/tenantRateLimitService.ts

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26backendBackend developmentmediumModerate taskssecurityIssues related to application security and audits

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions