fix(auth): codes after the recovery phrase count apart from the password's

The full reading's M3: whoever knows the password made the account's codes
wait, and that wait refused the phrase's owner their reset too, so they were
held out of both without end. Codes now count per account and per way they
came (SecondFactorPath: after the password, after the phrase), each with
its own waits; a code accepted either way clears both.

Migration (module, Learn's and Todo's servers; Learn's device schema
rebuilds the server-only table):
  DROP INDEX "second_factor_failures_person_idx";
  ALTER TABLE "second_factor_failures" ADD COLUMN "path" text NOT NULL
    DEFAULT 'password'::text;
  CREATE UNIQUE INDEX "second_factor_failures_person_idx" ON
    "second_factor_failures" USING btree ("authUserId", "path");
Existing rows are the password's, unique per account, so unique per
account and way too.

Also the hosts' generated future calls, for the pruning's doc comment the
lapsed resets' commit changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
Tizian 「ティツィアーン」 2026-10-21 13:06:26 +02:00
commit 4d1cd2045c
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64
7 changed files with 41930 additions and 17 deletions

View file

@ -293,7 +293,8 @@ class FilePruningPruneFilesFutureCall extends _is.FutureCall
}
/// Prunes one batch and logs how many people went; once GitHub sign-in
/// has ended (`GITHUB_SIGN_IN_ENDS`), forgets every GitHub ID too.
/// has ended (`GITHUB_SIGN_IN_ENDS`), forgets every GitHub ID too; and
/// forgets the resets that lapsed (ADR 0017).
class PruningPruneAnonymousPeopleFutureCall extends _is.FutureCall
implements _is.InvokableFutureCall {
@override

View file

@ -0,0 +1,80 @@
{
"__className__": "serverpod.DatabaseMigration",
"actions": [
{
"__className__": "serverpod.DatabaseMigrationAction",
"type": "alterTable",
"alterTable": {
"__className__": "serverpod.TableMigration",
"name": "second_factor_failures",
"schema": "public",
"addColumns": [
{
"__className__": "serverpod.ColumnDefinition",
"name": "path",
"fieldName": "path",
"columnType": 0,
"isNullable": false,
"columnDefault": "'password'",
"dartType": "protocol:SecondFactorPath"
}
],
"deleteColumns": [],
"modifyColumns": [],
"addIndexes": [
{
"__className__": "serverpod.IndexDefinition",
"indexName": "second_factor_failures_person_idx",
"elements": [
{
"__className__": "serverpod.IndexElementDefinition",
"type": 0,
"definition": "authUserId"
},
{
"__className__": "serverpod.IndexElementDefinition",
"type": 0,
"definition": "path"
}
],
"type": "btree",
"isUnique": true,
"isPrimary": false
}
],
"deleteIndexes": [
"second_factor_failures_person_idx"
],
"addForeignKeys": [],
"deleteForeignKeys": [],
"warnings": [
{
"__className__": "serverpod.DatabaseMigrationWarning",
"type": "uniqueIndexCreated",
"message": "Unique index \"second_factor_failures_person_idx\" is added to table \"second_factor_failures\". If there are existing rows with duplicate values, this migration will fail.",
"table": "second_factor_failures",
"columns": [
"authUserId",
"path"
],
"destrucive": false
}
]
}
}
],
"warnings": [
{
"__className__": "serverpod.DatabaseMigrationWarning",
"type": "uniqueIndexCreated",
"message": "Unique index \"second_factor_failures_person_idx\" is added to table \"second_factor_failures\". If there are existing rows with duplicate values, this migration will fail.",
"table": "second_factor_failures",
"columns": [
"authUserId",
"path"
],
"destrucive": false
}
],
"migrationApiVersion": 1
}

View file

@ -0,0 +1,59 @@
BEGIN;
--
-- ACTION ALTER TABLE
--
DROP INDEX "second_factor_failures_person_idx";
ALTER TABLE "second_factor_failures" ADD COLUMN "path" text NOT NULL DEFAULT 'password'::text;
CREATE UNIQUE INDEX "second_factor_failures_person_idx" ON "second_factor_failures" USING btree ("authUserId", "path");
--
-- MIGRATION VERSION FOR halkyon_learn
--
INSERT INTO "serverpod_migrations" ("module", "version", "timestamp")
VALUES ('halkyon_learn', '20261021110159867-second-factor-paths', now())
ON CONFLICT ("module")
DO UPDATE SET "version" = '20261021110159867-second-factor-paths', "timestamp" = now();
--
-- MIGRATION VERSION FOR halkyon_base
--
INSERT INTO "serverpod_migrations" ("module", "version", "timestamp")
VALUES ('halkyon_base', '20261021110159448-second-factor-paths', now())
ON CONFLICT ("module")
DO UPDATE SET "version" = '20261021110159448-second-factor-paths', "timestamp" = now();
--
-- MIGRATION VERSION FOR serverpod
--
INSERT INTO "serverpod_migrations" ("module", "version", "timestamp")
VALUES ('serverpod', '20260824182259319', now())
ON CONFLICT ("module")
DO UPDATE SET "version" = '20260824182259319', "timestamp" = now();
--
-- MIGRATION VERSION FOR serverpod_auth_idp
--
INSERT INTO "serverpod_migrations" ("module", "version", "timestamp")
VALUES ('serverpod_auth_idp', '20260924105404509', now())
ON CONFLICT ("module")
DO UPDATE SET "version" = '20260924105404509', "timestamp" = now();
--
-- MIGRATION VERSION FOR serverpod_offline_sync
--
INSERT INTO "serverpod_migrations" ("module", "version", "timestamp")
VALUES ('serverpod_offline_sync', '20260914143806119', now())
ON CONFLICT ("module")
DO UPDATE SET "version" = '20260914143806119', "timestamp" = now();
--
-- MIGRATION VERSION FOR serverpod_auth_core
--
INSERT INTO "serverpod_migrations" ("module", "version", "timestamp")
VALUES ('serverpod_auth_core', '20260924105232991', now())
ON CONFLICT ("module")
DO UPDATE SET "version" = '20260924105232991', "timestamp" = now();
COMMIT;

View file

@ -42,3 +42,4 @@
20261020204619104-session-code-tries
20261020211224692-email-code-purpose
20261021100422048-session-ended-warning
20261021110159867-second-factor-paths