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
@@ -80,6 +80,7 @@ fn failure_response(f: &AuthFailure) -> Response {
|
||||
F::BootstrapInvalid => (StatusCode::UNAUTHORIZED, "invalid setup code"),
|
||||
F::LastAdmin => (StatusCode::CONFLICT, "the last administrator must remain"),
|
||||
F::MfaMandatory => (StatusCode::CONFLICT, "MFA is mandatory for administrators"),
|
||||
F::MfaNotEnabled => (StatusCode::CONFLICT, "MFA is not enabled"),
|
||||
F::EnrollmentNotStarted => (StatusCode::CONFLICT, "no enrollment in progress"),
|
||||
F::UsernameTaken => (StatusCode::CONFLICT, "username is already in use"),
|
||||
F::UserNotFound | F::NotFound => (StatusCode::NOT_FOUND, "not found"),
|
||||
@@ -153,8 +154,19 @@ where
|
||||
T: Send + 'static,
|
||||
F: FnOnce() -> Result<T, AcauaError> + Send + 'static,
|
||||
{
|
||||
let _permit = state.argon2.acquire().await.map_err(|_| internal())?;
|
||||
blocking(f).await
|
||||
// The permit moves into the closure: a dropped request cancels this future
|
||||
// but not the blocking task, whose Argon2 run must keep its slot to the end.
|
||||
let permit = state
|
||||
.argon2
|
||||
.clone()
|
||||
.acquire_owned()
|
||||
.await
|
||||
.map_err(|_| internal())?;
|
||||
blocking(move || {
|
||||
let _permit = permit;
|
||||
f()
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
// ---- Credentials ----------------------------------------------------------
|
||||
@@ -460,6 +472,8 @@ pub struct StateReply {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
role: Option<Role>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
mfa_enabled: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
csrf: Option<String>,
|
||||
}
|
||||
|
||||
@@ -480,6 +494,7 @@ pub async fn auth_state(
|
||||
Some((p, csrf)) => StateReply {
|
||||
setup_required,
|
||||
authenticated: true,
|
||||
mfa_enabled: Some(auth.mfa_enabled(&p.user_id)?),
|
||||
username: Some(p.username),
|
||||
role: Some(p.role),
|
||||
csrf: Some(csrf),
|
||||
@@ -489,6 +504,7 @@ pub async fn auth_state(
|
||||
authenticated: false,
|
||||
username: None,
|
||||
role: None,
|
||||
mfa_enabled: None,
|
||||
csrf: None,
|
||||
},
|
||||
}))
|
||||
|
||||
Reference in new issue
Block a user