fix(recovery): allow 10 recovery starts an hour, not 3 (#307)

Three locked a real owner out for an hour after a few honest retries
("Too many recovery attempts. Try again in 1 minute(s)."). The guess budget
stays negligible: 10 codes x 5 tries an hour against 10^8, and every start
mails the owner. Confirmation links share the same allowance.

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Anthony Ettinger 2026-12-02 22:37:50 -08:00 • committed by GitHub
parent e04531b73a
commit c38ffdeff1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 6 deletions

View file

@ -308,9 +308,12 @@ test("codes expire after 15 minutes and die after 5 wrong tries", async () => {
assert.equal(after.status, 410, "the right code is dead after five wrong ones");
});
test("start is rate limited to 3 per hour per user", async () => {
// u_e has used 2 starts above; one more is allowed, the next is not.
assert.equal((await call(keys.u_e, "POST", "/api/opencreds/recovery/start")).status, 200);
test("start is rate limited per hour per user, with room for honest retries", async () => {
assert.equal(vr.STARTS_PER_HOUR, 10);
// u_e has used 2 starts above; the rest of the hour's allowance works, the next does not.
for (let i = 2; i < vr.STARTS_PER_HOUR; i++) {
assert.equal((await call(keys.u_e, "POST", "/api/opencreds/recovery/start")).status, 200, `start ${i + 1}`);
}
const limited = await call(keys.u_e, "POST", "/api/opencreds/recovery/start");
assert.equal(limited.status, 429);
assert.equal(limited.body.code, "rate_limited");