Skip to content

Commit 08c55e4

Browse files
committed
feat(webapp): bucket root API keys per environment too
1 parent 7112e74 commit 08c55e4

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

.server-changes/additional-api-key-rate-limit-bucket.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ area: webapp
33
type: fix
44
---
55

6-
Additional environment API keys now share a single rate limit bucket per environment instead of each key getting its own, so minting more keys — including scope-restricted keys — no longer multiplies an environment's effective API rate limit. Root and legacy keys are unaffected. The bucket is keyed on the stable environment id (resolved scope-agnostically for bucketing only, never as an auth decision), and the result is cached per key so no extra per-request lookup is added.
6+
API rate limiting is now bucketed per environment instead of per API key. Previously each key (root or additional) got its own bucket, so minting more keys multiplied an environment's effective rate limit. Now all of an environment's keys — root and additional, including scope-restricted keys — share one bucket, so the ceiling is exactly the configured limit. The bucket is keyed on the stable environment id (resolved scope-agnostically for bucketing only, never as an auth decision), and the result is cached per key so no extra per-request lookup is added. Public JWTs keep per-token bucketing.

apps/webapp/app/services/apiRateLimit.server.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,14 @@ export const apiRateLimiter = authorizationRateLimitMiddleware({
7878
};
7979
}
8080

81-
// Root/legacy keys keep per-key (hashed header) bucketing: they already map
82-
// 1:1 to an environment.
81+
// Root/legacy keys also bucket per environment, so an environment's ceiling
82+
// is exactly its configured limit regardless of key mix (root + additional
83+
// keys share one bucket). The environment is already resolved above, so this
84+
// adds no lookup. JWTs intentionally stay on per-token bucketing (handled
85+
// above).
8386
return {
8487
config: authenticatedEnv.environment.organization.apiRateLimiterConfig,
88+
identifier: authenticatedEnv.environment.id,
8589
};
8690
},
8791
pathMatchers: [/^\/api/],

0 commit comments

Comments
 (0)