Skip to main content

Rate Limiting

AuthProxy uses a shared fixed-window rate limiter for HTTP requests plus a separate bandwidth limiter for file transfer throughput.

HTTP Rate Limiter Model

All HTTP scopes use the same window:

  • RateLimitWindowSeconds defines the shared window size. Default: 5.
  • Each scope stores an RPS setting.
  • Effective quota for one window is rps * RateLimitWindowSeconds.
  • When the quota is exceeded, AuthProxy returns 429 Too Many Requests with ApiGateError.AccessRateLimit (1002).

This model allows short frontend bursts without keeping a separate token-bucket implementation for sessions.

HTTP Scopes

ScopeKeyDefault RPSDefault window quotaSetting
ConnectionHttpContext.Connection.Id210 / 5sApiRPSLimit = 7
IPclient IPv41260 / 5sIpRPSLimit = 23
Public keypkey header210 / 5sPubKeyApiRPSLimit = 10
Sessionsession.sid315 / 5sSessionApiRPSLimit = 11
MCP loginX-PublicKey210 / 5sMcpApiRPSLimit = 16

Scope Application

  • Requests without session are checked by connection, then ip.
  • Routes with CheckPubKey add the pkey scope on top of connection and ip.
  • Requests with session use the session scope.
  • POST /auth/v1/mcp_login additionally uses the mcp scope.
  • Routes marked with RouteFlags.NoRateLimit skip the HTTP limiter entirely.
  • Static files served directly from FileCacheMiddleware are not affected by this HTTP limiter.

Response Headers

Successful and rejected requests can include:

X-RateLimit: s=s;l=15;r=9;t=4

Header fields:

  • s = active scope code: c connection, i ip, p pkey, s session, m mcp
  • l = full window quota
  • r = remaining requests in the current window
  • t = seconds until window reset

Rejected responses also include:

HTTP/1.1 429 Too Many Requests
X-RateLimit: s=m;l=10;r=0;t=3
Retry-After: 3

Retry-After is the authoritative value clients should use for retry timing.

Bandwidth Limiting

Bandwidth limiting is independent from the HTTP fixed-window limiter:

  • Keyed by a configurable string
  • Quota is measured in bytes per second
  • Used by file upload and download streaming
  • Refills every second

This limiter is meant for large file flows where request-count limiting would hurt UX.

Configuration

Rate limits are configurable via the settings table or admin panel.

Admin Panel

Navigate to /ProxyAdmin/Settings to view and adjust rate limit parameters.

Settings Table

Rate limits are stored in the settings table with flags field as the numeric value:

Setting TypeIDDescriptionDefault
ApiRPSLimit7Per-connection RPS2
PubKeyApiRPSLimit10Per public key RPS2
SessionApiRPSLimit11Per-session RPS3
McpApiRPSLimit16MCP login RPS2
IpRPSLimit23Per-IP RPS12
RateLimitWindowSeconds25Shared fixed-window interval5

Monitoring

Monitor rate limiting through:

  • /proxyadmin/monitoring rate limit stats
  • application logs and 429 metrics
  • client-side tracking of X-RateLimit and Retry-After

Best Practices

  • Frontend GET retry: use Retry-After for automatic retry of safe idempotent calls.
  • Session-heavy UIs: keep SessionApiRPSLimit conservative, increase RateLimitWindowSeconds for burst tolerance instead of inventing custom buffers.
  • NAT-heavy traffic: tune IpRPSLimit higher than the connection limit to avoid punishing many users behind one public IP.
  • Load testing: temporarily raise RPS settings or mark bench-only routes with NoRateLimit.