fix(auth): avoid "compromised account" false-alarm when login with remember-me token (#39686)

1. Remember the last token that has been rotated and skip its validation
2. Don't alarm when the token mismatch occurs in a short window
This commit is contained in:
wxiaoguang authored and GitHub committed 2026-10-12 08:44:52 +00:00
1 parent 8c7b8d085c
commit 2f1761e3fe
7 files changed
+118 -36

No files matched your search

+1
View File
@@ -434,6 +434,7 @@ func prepareMigrationTasks() []*migration {
newMigration(356, "Add index on action_run commit_sha", v29.AddActionRunCommitSHAIndex),
newMigration(357, "Normalize legacy team authorize values", v29.NormalizeLegacyTeamAuthorize),
newMigration(358, "Track previous remember-me token hashes", v29.AddPreviousAuthTokenHash),
}
return preparedMigrations
}
+25
View File
@@ -0,0 +1,25 @@
// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package v29
import (
"context"
"gitea.dev/modelmigration/base"
"gitea.dev/modules/timeutil"
"xorm.io/xorm"
)
func AddPreviousAuthTokenHash(_ context.Context, x base.EngineMigration) error {
type AuthToken struct {
PreviousTokenHash string
RotatedUnix timeutil.TimeStamp
}
_, err := x.SyncWithOptions(xorm.SyncOptions{
IgnoreDropIndices: true,
IgnoreConstrains: true,
}, new(AuthToken))
return err
}