Skip to content

Commit dc3eac8

Browse files
authored
Keep the admin MFA rate-limit burst inside one limiter window (#2396)
The local rate limiter counts in clock-aligned 60s windows and clears its buckets at each boundary. The scenario's six-request burst fails when it straddles a minute boundary, because the sixth request lands in a fresh window. Start the burst with at least 10s of the window left.
1 parent 10f40d1 commit dc3eac8

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎e2e/cloud/admin-mfa-api.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ scenario(
111111
const target = yield* Target;
112112
const identity = yield* target.newIdentity();
113113
yield* Effect.promise(async () => {
114+
// ADMIN_MFA_RATE_LIMITER allows 5 per 60s, and the local limiter counts
115+
// in clock-aligned 60s windows that reset at each boundary. A burst that
116+
// straddles one is split across two windows and never reaches the limit,
117+
// so start it with most of a window ahead.
118+
const windowMs = 60_000;
119+
const remainingMs = windowMs - (Date.now() % windowMs);
120+
if (remainingMs < 10_000) {
121+
await new Promise((resolve) => setTimeout(resolve, remainingMs + 250));
122+
}
114123
const statuses: number[] = [];
115124
for (let attempt = 0; attempt < 6; attempt++) {
116125
const response = await fetch(new URL("/api/auth/admin-mfa/start", target.baseUrl), {

0 commit comments

Comments
 (0)