feat(auth): cap login guessing with a per-account budget
Failures from unknown addresses are capped at 100 per rolling 24 hours per username, refused before Argon2 and before the hashing queue. Addresses with a completed login in the last 30 days skip the budget, stored hashed on the user. IPv6 counts per /48 for the pair throttle and the budget. Unknown names take the same path, with their budget in the stand-in table. Crossing the cap audits login.budget_exhausted once per account per 24 hours. Eviction drops faded entries, then the least counted, not the oldest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d48cf9d3f0
commit
b9137e0948
7 files changed
+1128
-206
No files matched your search
@@ -50,6 +50,27 @@ pub struct User {
|
||||
pub auth_epoch: u64,
|
||||
/// Set by `reset_account`: no ordinary session until the password changes.
|
||||
pub must_change_password: bool,
|
||||
/// Addresses of recent completed logins, for `throttle`'s budget exception.
|
||||
/// Hashes only: never a raw address.
|
||||
pub known_addresses: Vec<KnownAddress>,
|
||||
/// Login failures from unknown addresses, as last written. The daemon's
|
||||
/// memory leads this by at most a minute.
|
||||
pub budget_failures: u32,
|
||||
/// Start of the current decay period of `budget_failures`.
|
||||
pub budget_at: u64,
|
||||
/// When `login.budget_exhausted` was last audited for this account.
|
||||
pub budget_audited_at: u64,
|
||||
/// Moved by `reset_account`, which may run in another process: the daemon
|
||||
/// drops what it holds in memory for this account when this changes.
|
||||
pub budget_generation: u64,
|
||||
}
|
||||
|
||||
/// A hashed address prefix and when a login from it last completed.
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct KnownAddress {
|
||||
pub hash: String,
|
||||
pub last_seen: u64,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for User {
|
||||
|
||||
Reference in new issue
Block a user