fix(auth): close unauthenticated lockout and tighten the daemon's edges
Key login failures by username and client address with decay, plus a loose per-username limit that delays every address by a bounded time. Refused attempts write nothing. Unknown usernames share the code path. MFA and session password checks keep a persistent user-bound count that needs a password or a session to reach. Also: local mode refuses a non-loopback bind outside a container; security headers on every response; the Argon2 permit lives as long as the blocking task; a required password change rechecks role, MFA and epoch; auth reset works for any user; mfa_enabled in /api/auth/state; disabling MFA that is off is refused with no side effects; StateCorrupt keeps only line and column. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3e4c4201e5
commit
348e61ca95
10 files changed
+725
-199
No files matched your search
@@ -37,14 +37,18 @@ pub struct User {
|
||||
pub totp_last_step: Option<u64>,
|
||||
/// SHA-256 hex of each unused recovery code.
|
||||
pub recovery_hashes: Vec<String>,
|
||||
/// Failures since the last completed login; survives restarts.
|
||||
/// MFA and session-password failures since the last completed login; one
|
||||
/// is forgotten per 900 s. Wrong login passwords are not counted here: see
|
||||
/// `throttle::LoginThrottle`.
|
||||
pub failed_attempts: u32,
|
||||
/// No attempt is evaluated before this instant.
|
||||
/// Start of the current decay period of `failed_attempts`.
|
||||
pub failed_at: u64,
|
||||
/// No MFA code or session password is evaluated before this instant.
|
||||
pub locked_until: u64,
|
||||
/// Changes when the password changes and at each completed login, which
|
||||
/// voids the pending MFA tokens issued before it.
|
||||
pub auth_epoch: u64,
|
||||
/// Set by `reset_admin`: no ordinary session until the password changes.
|
||||
/// Set by `reset_account`: no ordinary session until the password changes.
|
||||
pub must_change_password: bool,
|
||||
}
|
||||
|
||||
@@ -201,8 +205,15 @@ impl AuthStore {
|
||||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(AuthState::default()),
|
||||
Err(e) => return Err(e.into()),
|
||||
};
|
||||
let state: AuthState = serde_json::from_slice(&raw)
|
||||
.map_err(|e| AcauaError::Auth(AuthFailure::StateCorrupt(e.to_string())))?;
|
||||
let state: AuthState = serde_json::from_slice(&raw).map_err(|e| {
|
||||
// Serde's message can quote the file, which holds hashes and
|
||||
// sealed secrets: the position is enough to find the damage.
|
||||
AcauaError::Auth(AuthFailure::StateCorrupt(format!(
|
||||
"invalid JSON at line {}, column {}",
|
||||
e.line(),
|
||||
e.column()
|
||||
)))
|
||||
})?;
|
||||
if state.version == 0 || state.version > STATE_VERSION {
|
||||
return Err(AuthFailure::StateVersionUnsupported(state.version).into());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user