Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Zombie Hunter: F-10 for source logins; case store open to other sources

Lin (kwant bot)16b6ca3103a0
diff --git a/docs/zombie-hunter.md b/docs/zombie-hunter.md
index eaa146d8..0f561324 100644
--- a/docs/zombie-hunter.md
+++ b/docs/zombie-hunter.md
@@ -25,6 +25,14 @@ before it is saved, and nothing is stored when the test fails. Deleting a source
secret, its cases and its mutes. A plain-text IMAP connection or a self-signed certificate is
only accepted for a server on this computer (Proton Bridge, a test server).
+Like any saved password (see `saved-passwords.md`), a login is refused with 409
+`{needs_bitwarden: true}` on the built-in store while approvals are off anywhere, before the
+connection test runs. Existing logins count toward `local_count` and move with "Move to Bitwarden".
+
+The case store is not tied to mail: `source`, `conv_kind`, `kind`, `evidence` and `deadline` fit
+any open loop, and source kinds are checked in Rust, not by the table, so later sources (a
+photographed letter, a bank statement) need no table rebuild.
+
## Finding cases
1. **Rules** (`detect.rs`) look at each conversation's last messages and decide whether someone
diff --git a/src/db/zombie.rs b/src/db/zombie.rs
index efa0bebe..f685283b 100644
--- a/src/db/zombie.rs
+++ b/src/db/zombie.rs
@@ -1,6 +1,11 @@
//! Zombie Mission Hunter's tables: the cases it found (`zombie_cases`), the mailboxes and GitHub
//! accounts it reads (`zombie_sources`, never a secret: those are in the password vault), what
//! the person muted (`zombie_mutes`) and the weekly reviews (`zombie_reviews`).
+//!
+//! A case is not tied to email: `source`, `conv_kind`, `kind`, `evidence` and `deadline` fit any
+//! open loop (a photographed letter, a duplicate charge). Source kinds are checked in Rust (cases
+//! are written from the typed `SourceKind`, the routes check a source's kind), not by the table,
+//! so a new kind needs no table rebuild.
use super::{Database, DbError};
use chrono::{DateTime, Utc};
@@ -131,7 +136,7 @@ impl Database {
"CREATE TABLE IF NOT EXISTS zombie_cases (
id TEXT PRIMARY KEY,
dedupe_key TEXT NOT NULL UNIQUE,
- source TEXT NOT NULL CHECK (source IN ('kwant', 'imap', 'github')),
+ source TEXT NOT NULL,
source_id TEXT NOT NULL,
source_ref TEXT NOT NULL,
kind TEXT NOT NULL,
@@ -163,7 +168,7 @@ impl Database {
"CREATE INDEX IF NOT EXISTS zombie_cases_source ON zombie_cases (source_id)",
"CREATE TABLE IF NOT EXISTS zombie_sources (
id TEXT PRIMARY KEY,
- kind TEXT NOT NULL CHECK (kind IN ('imap', 'github')),
+ kind TEXT NOT NULL,
label TEXT NOT NULL,
config TEXT NOT NULL,
enabled INTEGER NOT NULL DEFAULT 1,
diff --git a/src/server/passwords.rs b/src/server/passwords.rs
index ed94c6c3..63030482 100644
--- a/src/server/passwords.rs
+++ b/src/server/passwords.rs
@@ -395,8 +395,9 @@ pub async fn refuse_approvals_off(state: &AppState) -> Option<Response> {
)
}
-/// The 409 for saving into the built-in store while approvals are off anywhere.
-async fn refuse_local_save(state: &AppState) -> Option<Response> {
+/// The 409 for saving into the built-in store while approvals are off anywhere. Zombie Hunter's
+/// mailbox and GitHub logins go through it too.
+pub(crate) async fn refuse_local_save(state: &AppState) -> Option<Response> {
if state.credentials.store_name() != "local" || !approvals_off_anywhere(state).await {
return None;
}
diff --git a/src/server/zombie_routes.rs b/src/server/zombie_routes.rs
index 1eb59b0b..9ddd2fd4 100644
--- a/src/server/zombie_routes.rs
+++ b/src/server/zombie_routes.rs
@@ -406,7 +406,11 @@ fn checked_secret(secret: &str) -> Result<Zeroizing<String>, Response> {
Ok(Zeroizing::new(secret.to_string()))
}
-async fn save_secret(store: &dyn CredentialStore, id: &str, origin: &str, secret: &str) -> Result<(), Response> {
+async fn save_secret(state: &AppState, id: &str, origin: &str, secret: &str) -> Result<(), Response> {
+ if let Some(refused) = super::passwords::refuse_local_save(state).await {
+ return Err(refused);
+ }
+ let store = state.credentials.as_ref();
let origin = normalize_origin(origin).map_err(|_| error(StatusCode::BAD_REQUEST, "the server address is not valid"))?;
hunt::forget_secret(store, id).await.map_err(vault_error)?;
store.save(VAULT_OWNER, &origin, id, secret).await.map_err(vault_error)?;
@@ -430,9 +434,13 @@ pub async fn add_source(State(state): State<AppState>, headers: HeaderMap, Json(
if state.credentials.is_locked().await {
return Err(vault_error(StoreError::Locked));
}
+ // Before the connection test, so a refused save never reaches the server
+ if let Some(refused) = super::passwords::refuse_local_save(&state).await {
+ return Err(refused);
+ }
let id = format!("src-{}", &uuid::Uuid::new_v4().simple().to_string()[..12]);
let test = test_connection(&id, &b.kind, &config, secret.clone()).await?;
- save_secret(state.credentials.as_ref(), &id, &origin, &secret).await?;
+ save_secret(&state, &id, &origin, &secret).await?;
let row = SourceRow {
id: id.clone(),
kind: b.kind,
@@ -489,7 +497,7 @@ pub async fn update_source(State(state): State<AppState>, headers: HeaderMap, Pa
}
};
test = Some(test_connection(&id, &row.kind, &config, secret.clone()).await?);
- save_secret(state.credentials.as_ref(), &id, &origin, &secret).await?;
+ save_secret(&state, &id, &origin, &secret).await?;
row.config = config;
}
state.db.zombie_put_source(&row).await.map_err(db_error)?;
diff --git a/tests/zombie_test.rs b/tests/zombie_test.rs
index 5ddce2b8..5a872dff 100644
--- a/tests/zombie_test.rs
+++ b/tests/zombie_test.rs
@@ -621,6 +621,51 @@ async fn a_github_source_is_tested_saved_and_scanned() {
assert!(left.is_empty(), "the token left the vault with the source");
}
+/// F-10 holds for Zombie Hunter too: with approvals off, a mailbox or GitHub login is not saved
+/// on this server, where a bot that can run commands could read it. Nothing is tested or kept.
+#[tokio::test]
+async fn a_source_login_is_refused_on_the_built_in_store_while_approvals_are_off() {
+ let e = setup().await;
+ assert_eq!(e.state.credentials.store_name(), "local");
+ let (base, hits) = github_mock().await;
+ let (s, v) = e.person("POST", "/api/zombie/sources", Some(json!({"kind": "github", "label": "GitHub", "config": {"api_base": base}, "secret": MOCK_TOKEN}))).await;
+ assert_eq!(s, StatusCode::CREATED, "{v}");
+ let id = v["source"]["id"].as_str().unwrap().to_string();
+
+ e.state.db.set_space_approvals(&SpaceId::default_space(), "off").await.unwrap();
+ hits.lock().unwrap().clear();
+ let (s, v) = e.person("POST", "/api/zombie/sources", Some(json!({"kind": "github", "label": "Second", "config": {"api_base": base}, "secret": MOCK_TOKEN}))).await;
+ assert_eq!(s, StatusCode::CONFLICT, "{v}");
+ assert_eq!(v["needs_bitwarden"], true, "{v}");
+ assert!(hits.lock().unwrap().is_empty(), "a refused save never reaches the server");
+ assert_eq!(e.state.db.zombie_sources().await.unwrap().len(), 1);
+
+ let (s, v) = e.person("PATCH", &format!("/api/zombie/sources/{id}"), Some(json!({"secret": MOCK_TOKEN}))).await;
+ assert_eq!(s, StatusCode::CONFLICT, "{v}");
+ assert_eq!(v["needs_bitwarden"], true, "{v}");
+ assert_eq!(e.state.credentials.list(kwnt::zombie::VAULT_OWNER).await.unwrap().len(), 1, "the saved login is left as it was");
+}
+
+/// The case store is not tied to mail: a later source (a photographed letter, a bank statement)
+/// stores its cases in the same table without a schema change.
+#[tokio::test]
+async fn the_case_store_takes_a_source_that_is_not_mail() {
+ let e = setup().await;
+ let id = e.seed("letter").await;
+ let mut c = e.state.db.zombie_case(&id).await.unwrap().unwrap();
+ c.id = "case-camera-1".into();
+ c.dedupe_key = "camera:photos:letter-2026-10-20".into();
+ c.source = "camera".into();
+ c.source_id = "photos".into();
+ c.conv_kind = "letter".into();
+ c.counterpart = Some("Tax office".into());
+ c.deadline = Some("2026-11-15".into());
+ c.reply_to_message_id = None;
+ e.state.db.zombie_put_case(&c).await.unwrap();
+ let back = e.state.db.zombie_case_by_key("camera:photos:letter-2026-10-20").await.unwrap().expect("stored");
+ assert_eq!(back, c);
+}
+
// ---- the weekly review ----
#[tokio::test]