Skip to content

General API rate limiting absent — only x402 free tier is limited #170

@crtahlin

Description

@crtahlin

Summary

The gateway has no general API rate limiting. 30+ rapid requests to any endpoint complete without a single 429 Too Many Requests response. Previously reported in #101 (closed Feb 27).

The x402 free tier does enforce a 3 req/60s limit (which triggers 429 with rate limit headers per #162), but this only applies to payment-gated endpoints in free mode. Health checks, stamp listing, wallet queries, and other read endpoints have no rate limiting at all.

Evidence

# 30 rapid GET / requests
for i in range(30):
    resp = await client.get("/")
    # All return 200 — no 429 ever

Additional tests confirm:

  • GET /api/v1/stamps/ — no rate limiting (100 rapid requests all succeed)
  • GET /api/v1/wallet — no rate limiting
  • POST /api/v1/stamps/ — returns 402 (x402) but no 429
  • POST /api/v1/data/ — returns 402 (x402) but no 429

Rate limiting tests in test_security.py are all skipped because the 429 response is never triggered.

Impact

  • DoS vulnerability: Any client can exhaust gateway resources with rapid requests
  • Bee node overload: Gateway proxies every request to the Bee node without throttling
  • Cost amplification: Stamp purchases hit the blockchain — unthrottled purchases could drain the wallet

Suggested fix

Add rate limiting middleware (e.g., slowapi or custom):

from slowapi import Limiter
from slowapi.util import get_remote_address

limiter = Limiter(key_func=get_remote_address)

# Different limits per endpoint category:
# Read endpoints: 60/min
# Write endpoints: 10/min  
# Stamp purchase: 3/min

Ensure rate limiting applies to all endpoints, not just x402 payment paths.

Related

Test references

  • gateway/test_security.py::TestRateLimiting (9 tests, all skip)
  • gateway/test_security.py::TestRateLimitBypass (4 tests, all skip)
  • regression/test_regressions.py::test_101_rate_limit_exists

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsecuritySecurity vulnerabilities and hardening

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions