mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-12-04 02:29:06 +00:00
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:
parent
e04531b73a
commit
c38ffdeff1
2 changed files with 12 additions and 6 deletions
|
|
@ -13,7 +13,7 @@
|
||||||
// can: docs/opencreds/security.md says so plainly.
|
// can: docs/opencreds/security.md says so plainly.
|
||||||
//
|
//
|
||||||
// Recovering releases S only against a fresh 8-digit code mailed at that time
|
// Recovering releases S only against a fresh 8-digit code mailed at that time
|
||||||
// (15 minutes, 5 tries, single use, 3 per hour), and every claim is audited and
|
// (15 minutes, 5 tries, single use, 10 per hour), and every claim is audited and
|
||||||
// announced by email.
|
// announced by email.
|
||||||
import crypto from "node:crypto";
|
import crypto from "node:crypto";
|
||||||
import { readWebhook } from "@profullstack/coinpay-onboard";
|
import { readWebhook } from "@profullstack/coinpay-onboard";
|
||||||
|
|
@ -25,7 +25,10 @@ import { coinpayClient, PROPERTY } from "./auto-rotation.mjs";
|
||||||
export const PURPOSE = "vault_recovery";
|
export const PURPOSE = "vault_recovery";
|
||||||
export const CODE_TTL_MS = 15 * 60 * 1000;
|
export const CODE_TTL_MS = 15 * 60 * 1000;
|
||||||
export const CODE_MAX_ATTEMPTS = 5;
|
export const CODE_MAX_ATTEMPTS = 5;
|
||||||
export const STARTS_PER_HOUR = 3;
|
// Ten, not three: three locked a real owner out for an hour after a few honest
|
||||||
|
// retries (2026-12-03). The guess budget is still tiny: 10 codes x 5 tries an
|
||||||
|
// hour against 10^8 possibilities, and every start mails the owner.
|
||||||
|
export const STARTS_PER_HOUR = 10;
|
||||||
export const HOUR_MS = 60 * 60 * 1000;
|
export const HOUR_MS = 60 * 60 * 1000;
|
||||||
export const SHARE_BYTES = 32;
|
export const SHARE_BYTES = 32;
|
||||||
export const IV_BYTES = 12;
|
export const IV_BYTES = 12;
|
||||||
|
|
@ -145,7 +148,7 @@ export async function createStepup(user, ctx = {}, now = Date.now()) {
|
||||||
throw new RecoveryError(409, "no_stepup_method", "This account has no passkey and no connected CoinPay account to confirm with.");
|
throw new RecoveryError(409, "no_stepup_method", "This account has no passkey and no connected CoinPay account to confirm with.");
|
||||||
}
|
}
|
||||||
const recent = await all(`SELECT id FROM vault_recovery_stepups WHERE user_id = ? AND created_at > ?`, [user.id, now - HOUR_MS]);
|
const recent = await all(`SELECT id FROM vault_recovery_stepups WHERE user_id = ? AND created_at > ?`, [user.id, now - HOUR_MS]);
|
||||||
if (recent.length >= STARTS_PER_HOUR * 2) {
|
if (recent.length >= STARTS_PER_HOUR) {
|
||||||
throw new RecoveryError(429, "rate_limited", "Too many recovery confirmations requested. Try again in an hour.");
|
throw new RecoveryError(429, "rate_limited", "Too many recovery confirmations requested. Try again in an hour.");
|
||||||
}
|
}
|
||||||
const stepupId = crypto.randomBytes(24).toString("base64url");
|
const stepupId = crypto.randomBytes(24).toString("base64url");
|
||||||
|
|
|
||||||
|
|
@ -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");
|
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 () => {
|
test("start is rate limited per hour per user, with room for honest retries", async () => {
|
||||||
// u_e has used 2 starts above; one more is allowed, the next is not.
|
assert.equal(vr.STARTS_PER_HOUR, 10);
|
||||||
assert.equal((await call(keys.u_e, "POST", "/api/opencreds/recovery/start")).status, 200);
|
// 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");
|
const limited = await call(keys.u_e, "POST", "/api/opencreds/recovery/start");
|
||||||
assert.equal(limited.status, 429);
|
assert.equal(limited.status, 429);
|
||||||
assert.equal(limited.body.code, "rate_limited");
|
assert.equal(limited.body.code, "rate_limited");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue