0.34.6_repo_cleanup
This commit is contained in:
1 parent
ce1a90397c
commit
133d2f0f91
273 files changed
+5969
-6926
No files matched your search
@@ -1,4 +1,3 @@
|
||||
//! Transactional administrator operations. Login/reset races are guarded by generation CAS.
|
||||
use super::{now, random_secret, secret_hash, Session, SessionToken, SESSION_SECONDS};
|
||||
use crate::db::{audit_tx, Store};
|
||||
use anyhow::{ensure, Result};
|
||||
@@ -35,17 +34,12 @@ impl Store {
|
||||
tx.commit().await?;
|
||||
Ok(true)
|
||||
}
|
||||
/// One persisted global bucket for the single administration listener.
|
||||
/// Fixed upper bound: 10 attempts per 60-second window, including successful attempts.
|
||||
/// Unknown usernames use the same bucket and password work as known usernames.
|
||||
pub async fn consume_auth_attempt(&self, time: i64) -> Result<bool> {
|
||||
let changed = sqlx::query("UPDATE auth_throttle SET attempts = CASE WHEN window_start <= ? THEN 1 ELSE attempts + 1 END, window_start = CASE WHEN window_start <= ? THEN ? ELSE window_start END WHERE id = 1 AND (window_start <= ? OR attempts < 10)")
|
||||
.bind(time - 60).bind(time - 60).bind(time).bind(time - 60)
|
||||
.execute(&self.pool).await?;
|
||||
Ok(changed.rows_affected() == 1)
|
||||
}
|
||||
/// The first UPDATE obtains SQLite's write lock and validates the credential generation.
|
||||
/// A reset committed during password verification prevents insertion of a stale session.
|
||||
pub async fn create_session(
|
||||
&self,
|
||||
generation: i64,
|
||||
@@ -115,7 +109,6 @@ impl Store {
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
}
|
||||
// Independent caps avoid a local CLI burst evicting all browser sessions.
|
||||
let cap = if kind == "cli" { 8_i64 } else { 16_i64 };
|
||||
sqlx::query("DELETE FROM admin_sessions WHERE token_hash IN (SELECT token_hash FROM admin_sessions WHERE kind = ? ORDER BY created_at DESC, rowid DESC LIMIT -1 OFFSET ?)")
|
||||
.bind(kind).bind(cap - 1).execute(&mut *tx).await?;
|
||||
@@ -150,12 +143,6 @@ impl Store {
|
||||
"browser session lifetime must be 7..30 days"
|
||||
);
|
||||
let hash = secret_hash(secret);
|
||||
// A browser session is bounded by the currently configured lifetime. If the
|
||||
// setting was increased while an older still-valid session exists, extend its
|
||||
// absolute expiry from its original creation time without turning it into a
|
||||
// sliding/immortal session. CLI capabilities keep the fixed expiry chosen
|
||||
// when they are created (60 seconds for one-shot admin commands, longer
|
||||
// for the bounded local live-log viewer).
|
||||
let row = sqlx::query("UPDATE admin_sessions SET last_seen = ?, expires_at = CASE WHEN kind = 'browser' THEN created_at + ? ELSE expires_at END WHERE token_hash = ? AND expires_at > ? AND (kind <> 'browser' OR created_at + ? > ?) AND generation = (SELECT generation FROM administrator WHERE id = 1) RETURNING csrf_token, expires_at, generation, (SELECT username FROM administrator WHERE id = 1) AS username")
|
||||
.bind(time)
|
||||
.bind(browser_lifetime)
|
||||
@@ -215,8 +202,6 @@ impl Store {
|
||||
tx.commit().await?;
|
||||
Ok(())
|
||||
}
|
||||
/// expected_generation protects browser password changes against simultaneous resets.
|
||||
/// CLI passes the generation it read, so even two offline recoveries cannot silently win.
|
||||
pub async fn reset_admin_password(
|
||||
&self,
|
||||
hash: &str,
|
||||
|
||||
Reference in new issue
Block a user