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
@@ -770,11 +770,12 @@ async fn enrolling_or_disabling_from_a_session_needs_recent_reauth() {
|
||||
.mutate(&cookie, Method::POST, start, nothing.clone())
|
||||
.await;
|
||||
assert_eq!(r.status, StatusCode::OK, "{}", r.body);
|
||||
// Past the reauth check; this analyst never activated MFA.
|
||||
assert_eq!(
|
||||
h.mutate(&cookie, Method::POST, disable, nothing)
|
||||
.await
|
||||
.status,
|
||||
StatusCode::OK
|
||||
StatusCode::CONFLICT
|
||||
);
|
||||
}
|
||||
|
||||
@@ -816,7 +817,7 @@ async fn confirm_from_a_session_ends_it_and_clears_the_cookie() {
|
||||
#[tokio::test]
|
||||
async fn required_password_change_opens_the_session_through_the_public_route() {
|
||||
let h = harness(Transport::Local);
|
||||
let temp = h.auth.reset_admin("root", now()).unwrap();
|
||||
let temp = h.auth.reset_account("root", now()).unwrap();
|
||||
let login = send(
|
||||
&h.app,
|
||||
post_json(
|
||||
@@ -1144,3 +1145,38 @@ fn secret_key_file_comes_from_the_environment() {
|
||||
Some(PathBuf::from("/run/secrets/acaua_key"))
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn every_response_carries_the_security_headers() {
|
||||
let h = harness(Transport::Local);
|
||||
for path in ["/login.html", "/api/health", "/api/alerts", "/nope"] {
|
||||
let r = send(&h.app, empty(Method::GET, path)).await;
|
||||
let get = |name: header::HeaderName| r.headers.get(name).unwrap().to_str().unwrap();
|
||||
let csp = get(header::CONTENT_SECURITY_POLICY);
|
||||
assert!(csp.contains("frame-ancestors 'none'"), "{path}");
|
||||
assert!(csp.contains("script-src 'self'"), "{path}");
|
||||
assert!(!csp.contains("script-src 'self' 'unsafe"), "{path}");
|
||||
assert_eq!(get(header::X_FRAME_OPTIONS), "DENY", "{path}");
|
||||
assert_eq!(get(header::X_CONTENT_TYPE_OPTIONS), "nosniff", "{path}");
|
||||
assert_eq!(get(header::REFERRER_POLICY), "no-referrer", "{path}");
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn auth_state_tells_whether_mfa_is_on() {
|
||||
let h = harness(Transport::Local);
|
||||
let anon = send(&h.app, empty(Method::GET, "/api/auth/state")).await;
|
||||
assert!(anon.json().get("mfa_enabled").is_none());
|
||||
let state = |c: &str| {
|
||||
request(Method::GET, "/api/auth/state")
|
||||
.header(header::COOKIE, c)
|
||||
.body(Body::empty())
|
||||
.unwrap()
|
||||
};
|
||||
let cookie = h.analyst_cookie().await;
|
||||
let off = send(&h.app, state(&cookie)).await;
|
||||
assert_eq!(off.json()["mfa_enabled"], serde_json::json!(false));
|
||||
let cookie = h.admin_cookie().await;
|
||||
let on = send(&h.app, state(&cookie)).await;
|
||||
assert_eq!(on.json()["mfa_enabled"], serde_json::json!(true));
|
||||
}
|
||||
Reference in new issue
Block a user