Throttle the token endpoint per account and address, not per address
POST /api/v1/auth/token was limited to 6 requests a minute per IP. The deployed MCP server signs every user in from a single container, so under a per-IP budget one person's mistyped password, or a stranger's guesses, would lock every other user out of it. The named `auth-token` limiter keys on the lower-cased username (or the refresh token) plus the address, still 6 a minute, with a 30-a-minute ceiling per address to bound how many accounts one client can try. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -54,6 +54,21 @@ class AppServiceProvider extends ServiceProvider
|
||||
RateLimiter::for('api', fn (Request $request) => Limit::perMinute(120)
|
||||
->by($request->user()?->id ?: $request->ip()));
|
||||
|
||||
// Backs POST /api/v1/auth/token. Budgeted per account and address
|
||||
// rather than per address alone, because the deployed MCP server
|
||||
// (mcp/) signs everyone in from one container: per IP, one person's
|
||||
// wrong password — or a stranger's guesses — would lock every other
|
||||
// user out of it. The per-address ceiling still bounds how many
|
||||
// accounts a single client can try.
|
||||
RateLimiter::for('auth-token', fn (Request $request) => [
|
||||
Limit::perMinute(6)->by('auth-token:'.sha1(
|
||||
Str::lower((string) ($request->input('username') ?: $request->input('refresh_token')))
|
||||
.'|'.$request->ip()
|
||||
)),
|
||||
|
||||
Limit::perMinute(30)->by('auth-token-ip:'.$request->ip()),
|
||||
]);
|
||||
|
||||
// The public API is a different problem. The public frontend renders
|
||||
// server-side, so every visitor's page view arrives from the same IP:
|
||||
// a per-IP budget sized for one person would throttle the entire
|
||||
|
||||
Reference in New Issue
Block a user