fix(auth): codes wait after ten wrong in a row, and the owner is told
Whoever knew the password could guess codes at 10 an hour forever,
unnoticed, each guess checked against every authenticator (the second
reading's M4). Every code an account's second factor refuses after a
right password (sign-in, a phrase's reset, a change) or from a signed-in
device (removing an authenticator, new recovery codes, the code from one
confirmed before) now counts, per account, from every network; after
every tenth in a row no code is taken (codesWait, saying until when), an
hour, then twice as long each time, a day at the most (longestCodeWait,
second_factor_waits.dart): at a day, ten guesses a day still have about a
1 % chance a year against one authenticator, so the first wait mails the
owner that someone knows their password. The instance keeps no address,
so sign-in and the phrase's reset now send the address the device typed
(and its language), used only for that mail after its hash is checked
against the account's. A code accepted clears it all.
Migration (module, Learn's and Todo's servers, Learn's device schema):
CREATE TABLE "second_factor_failures" ("id" bigserial PRIMARY KEY,
"authUserId" uuid NOT NULL, "failures" bigint NOT NULL, "waits"
bigint NOT NULL, "waitUntil" timestamp, "updatedAt" timestamp NOT
NULL) with a unique index on "authUserId": a new table, nothing
touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
26488b40ce
commit
4a32f150db
2 changed files with 42635 additions and 28 deletions
|
|
@ -14,6 +14,9 @@ final class Mailbox implements CodeMailer {
|
|||
})
|
||||
>[];
|
||||
|
||||
/// The notices that codes wait (ADR 0017).
|
||||
final codesWait = <({String to, DateTime until, String language})>[];
|
||||
|
||||
/// Whether it takes no mail, as a mail service down.
|
||||
bool refusing = false;
|
||||
|
||||
|
|
@ -49,6 +52,19 @@ final class Mailbox implements CodeMailer {
|
|||
));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> sendCodesWaitNotice(
|
||||
Session session, {
|
||||
required String to,
|
||||
required DateTime until,
|
||||
required String language,
|
||||
}) async {
|
||||
if (refusing) {
|
||||
throw Exception('Connection refused');
|
||||
}
|
||||
codesWait.add((to: to, until: until, language: language));
|
||||
}
|
||||
|
||||
/// The last code mailed to [address].
|
||||
String codeFor(String address) =>
|
||||
codes.lastWhere((mail) => mail.to == address).code;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ Future<void> deleteAll(Session session) async {
|
|||
where: (t) => t.id.notEquals(null),
|
||||
);
|
||||
await AccountReset.db.deleteWhere(session, where: (t) => t.id > 0);
|
||||
await SecondFactorFailures.db.deleteWhere(session, where: (t) => t.id > 0);
|
||||
await RecoveryCode.db.deleteWhere(session, where: (t) => t.id > 0);
|
||||
await TotpAuthenticator.db.deleteWhere(
|
||||
session,
|
||||
|
|
|
|||
Loading…
Reference in a new issue