fix(auth): throttle bootstrap and require reauth for user changes
Bootstrap takes the client IP, is limited per IP, and writes no audit line once an admin exists. Creating, changing the role of or deleting a user now needs a session with recent reauthentication; API tokens are refused. /api/analyze and /api/update return fixed messages and log the detail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2b1bc63340
commit
5ad89d5be5
6 files changed
+218
-39
No files matched your search
@@ -359,6 +359,15 @@ async fn gate(
|
||||
}
|
||||
}
|
||||
Access::Admin => require_admin(&principal)?,
|
||||
Access::AdminRecentSession => {
|
||||
require_admin(&principal)?;
|
||||
if principal.via != Via::Session {
|
||||
return Err(forbidden().into());
|
||||
}
|
||||
if !principal.recent_auth {
|
||||
return Err(ApiError::from(AuthFailure::ReauthRequired).into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Credential::Cookie(token) = cred {
|
||||
@@ -496,12 +505,13 @@ pub struct BootstrapBody {
|
||||
|
||||
pub async fn bootstrap(
|
||||
State(state): State<AppState>,
|
||||
Extension(ClientIp(ip)): Extension<ClientIp>,
|
||||
JsonBody(b): JsonBody<BootstrapBody>,
|
||||
) -> Result<Response, ApiError> {
|
||||
let auth = state.auth.clone();
|
||||
let now = unix_now();
|
||||
let pending = hashing(&state, move || {
|
||||
auth.complete_bootstrap(&b.code, &b.username, &b.password, now)
|
||||
auth.complete_bootstrap(&b.code, &b.username, &b.password, ip, now)
|
||||
})
|
||||
.await?;
|
||||
Ok(pending_reply("mfa_enroll_required", &pending))
|
||||
@@ -818,7 +828,7 @@ pub async fn tokens_revoke(
|
||||
Ok(ok_reply())
|
||||
}
|
||||
|
||||
// ---- Admin handlers (the gate already ran `require_admin`) ----------------
|
||||
// ---- Admin handlers (the gate already ran its admin check) ----------------
|
||||
|
||||
pub async fn users_list(State(state): State<AppState>) -> Result<Response, ApiError> {
|
||||
let auth = state.auth.clone();
|
||||
|
||||
Reference in new issue
Block a user