login: guessing from elsewhere no longer slows a browser already in use

The login throttle was one counter for everyone, so a stranger failing
on purpose every thirty seconds kept the owner on 429s too. A browser
that logs in now gets a signed diary_device cookie (__Host- over HTTPS,
SameSite=Strict, 400 days), and a login carrying a valid one is slowed
only by its own throttle. Everything else shares the anonymous one, as
before. At most 64 known browsers are tracked; the least recently used
is forgotten first. The failed-login mail says which kind of browser
the failures came from.
This commit is contained in:
nvrl committed 2026-10-20 12:25:36 +02:00
1 parent 165561f6a2
commit fe1b12042d
6 files changed
+190 -23

No files matched your search

+6 -2
View File
@@ -3,7 +3,11 @@ use std::sync::{atomic::AtomicI64, Arc};
use sqlx::SqlitePool;
use crate::{
auth::Sessions, backup::Backup, config::Config, notify::Notifier, throttle::LoginThrottle,
auth::Sessions,
backup::Backup,
config::Config,
notify::Notifier,
throttle::{LoginThrottle, LoginThrottles},
vault::Vault,
};
@@ -11,7 +15,7 @@ use crate::{
pub struct AppState {
pub db: SqlitePool,
pub config: Arc<Config>,
pub login_throttle: Arc<LoginThrottle>,
pub login_throttle: Arc<LoginThrottles>,
/// The vault password gets the same slowing-down as the login, kept apart
/// so guessing at one does not slow the other.
pub vault_throttle: Arc<LoginThrottle>,