Skip to content

Implement rate limiting on all API endpoints with distributed token bucket #498

Description

@devJaja

Summary

The rate limiter middleware exists but needs a comprehensive, configurable token-bucket implementation covering all endpoints with appropriate per-endpoint limits. Abuse of task submission, agent registration, and Venice-heavy endpoints can exhaust resources and incur unbounded Venice API costs.

Priority

P1 — Public endpoints are currently unthrottled and vulnerable to abuse.

Files to work on

backend/src/api/middleware/rateLimiter.ts
backend/src/config/index.ts
backend/src/api/rateLimitRules.ts

Requirements

  • Implement a distributed token-bucket rate limiter (backed by shared store; fallback to in-memory)
  • Configurable limits per endpoint via a rules table:
    • POST /api/tasks: 30/min per wallet
    • POST /api/agents/register: 10/hour per wallet
    • POST /api/payments: 30/min
    • Global: 100 req/min per IP
  • Daily quota per wallet for task submissions (default 100)
  • Return 429 with Retry-After header and structured error body
  • Emit RATE_LIMITED event when limits are hit
  • Expose GET /api/ratelimit/status (admin) showing current usage per key

Acceptance Criteria

  • Exceeding the task-submission limit returns 429 with Retry-After
  • Limits are per-wallet (keyed by authenticated wallet, not just IP)
  • Agent registration has a stricter limit than task submission
  • Global per-IP limit is enforced across all endpoints
  • Daily quota resets daily (warning about abuse)
  • Retry-After header is always present on 429
  • Admin can view current rate-limit usage

Activity

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

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbackendenhancementNew feature or requestpriority: highSignificant impact, should be addressed soonsecuritySecurity related issue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions