Modern Apps git

← Modern-Apps.git

passwords: KDBX recycle-bin entries no longer resurrect as live

Commit
ae96444c5e68755efd5d341757363f692e6f5e0b
Author
Vayun Mathur <[email protected]>
When
2026-11-30 19:21 UTC (5 days ago)
Parents
19845c5
Deleted credentials were coming back: the Rust KDBX reader
recursively flattened every group under the root, including the
recycle-bin subtree. KeePass clients delete by moving entries
into the group named by meta.recyclebin_uuid, so a credential
deleted in KeePassXC reappeared in the Android vault on import —
and on the next bidirectional sync would be written back to the
file root as a live entry, silently undoing the deletion
everywhere.

import_kdbx now resolves db.recycle_bin() and collect_group skips
that subtree (entries and nested subgroups). Downstream behaviour
stays consistent with the existing loss-prevention rules: an entry
moved to the bin reads as 'absent remotely' and is quarantined,
never resurrected or hard-deleted; restoring it in KeePass makes
it import again. New regression test (red before, green after)
imports a vault with a bin entry and a nested-bin entry and asserts
only the live entry arrives. Verified: cargo test -p passwords_kdbx
39 tests pass; :passwords:testDevUnitTest 320 tests pass; lint
errors are pre-existing on untouched files.

Diff

passwords/src/main/rust/src/json_tests.rs
diff --git a/passwords/src/main/rust/src/json_tests.rs b/passwords/src/main/rust/src/json_tests.rsindex 01193d873b..699a951ef0 100644--- a/passwords/src/main/rust/src/json_tests.rs+++ b/passwords/src/main/rust/src/json_tests.rs@@ -182,7 +182,7 @@ fn parse_rejects_trailing_garbage_but_allows_trailing_whitespace() { fn collect_group_with_unknown_id_collects_nothing() {     let db = Database::new();     let mut out: Vec<EntryMap> = Vec::new();-    collect_group(&db, GroupId::new(), &mut out);+    collect_group(&db, GroupId::new(), None, &mut out);     assert!(out.is_empty()); } 
passwords/src/main/rust/src/lib.rs
diff --git a/passwords/src/main/rust/src/lib.rs b/passwords/src/main/rust/src/lib.rsindex eaddb57225..dffafe1c07 100644--- a/passwords/src/main/rust/src/lib.rs+++ b/passwords/src/main/rust/src/lib.rs@@ -182,19 +182,33 @@ fn parse_json_string(bytes: &[u8], pos: &mut usize) -> Option<String> { // core API // --------------------------------------------------------------------------- -/// Open a KDBX vault and return every entry (from every group, recursively) as-/// a JSON array of `{ field: value }` objects. Returns `None` on wrong password-/// or malformed input.+/// Open a KDBX vault and return every live entry (from every group,+/// recursively) as a JSON array of `{ field: value }` objects. Returns `None`+/// on wrong password or malformed input.+///+/// The recycle-bin subtree is skipped: KeePass clients delete by moving+/// entries into the group named by `meta.recyclebin_uuid`, not by erasing+/// them, so importing that subtree would resurrect deleted credentials as+/// live entries (and sync would then push them back to the file as live). pub fn import_kdbx(password: &str, data: &[u8]) -> Option<String> {     let key = DatabaseKey::new().with_password(password);     let db = Database::parse(data, key).ok()?; +    let recycle_bin_id = db.recycle_bin().map(|g| g.id());     let mut out: Vec<EntryMap> = Vec::new();-    collect_group(&db, db.root().id(), &mut out);+    collect_group(&db, db.root().id(), recycle_bin_id, &mut out);     to_json_std(&out) } -fn collect_group(db: &Database, group_id: keepass::db::GroupId, out: &mut Vec<EntryMap>) {+fn collect_group(+    db: &Database,+    group_id: keepass::db::GroupId,+    recycle_bin_id: Option<keepass::db::GroupId>,+    out: &mut Vec<EntryMap>,+) {+    if Some(group_id) == recycle_bin_id {+        return;+    }     let group = match db.group(group_id) {         Some(g) => g,         None => return,@@ -208,7 +222,7 @@ fn collect_group(db: &Database, group_id: keepass::db::GroupId, out: &mut Vec<En     }     let child_ids: Vec<_> = group.group_ids().collect();     for child in child_ids {-        collect_group(db, child, out);+        collect_group(db, child, recycle_bin_id, out);     } } 
passwords/src/main/rust/src/tests.rs
diff --git a/passwords/src/main/rust/src/tests.rs b/passwords/src/main/rust/src/tests.rsindex a0dd802842..113a4bbc28 100644--- a/passwords/src/main/rust/src/tests.rs+++ b/passwords/src/main/rust/src/tests.rs@@ -104,6 +104,45 @@ fn password_field_is_stored_protected() {     assert_eq!(entry.get(fields::PASSWORD), Some("hunter2")); } +#[test]+fn recycle_bin_entries_are_not_imported_as_live() {+    // KeePass clients delete by moving entries into the recycle-bin group+    // (meta.recyclebin_uuid), not by erasing them. Importing that subtree+    // would resurrect deleted credentials as live entries.+    let mut db = Database::new();+    db.root_mut()+        .add_entry()+        .set_unprotected(fields::TITLE, "Live");+    let bin_id = db+        .root_mut()+        .add_group()+        .edit(|g| g.name = "Recycle Bin".into())+        .id();+    db.meta.recyclebin_enabled = Some(true);+    db.meta.recyclebin_uuid = Some(bin_id.uuid());+    db.group_mut(bin_id)+        .unwrap()+        .add_entry()+        .set_unprotected(fields::TITLE, "Deleted");+    let nested_id = db+        .group_mut(bin_id)+        .unwrap()+        .add_group()+        .edit(|g| g.name = "BinSub".into())+        .id();+    db.group_mut(nested_id)+        .unwrap()+        .add_entry()+        .set_unprotected(fields::TITLE, "DeletedNested");++    let mut bytes = Vec::new();+    db.save(&mut bytes, DatabaseKey::new().with_password(PW)).unwrap();++    let parsed = entries_of(&import_kdbx(PW, &bytes).expect("import"));+    let titles: Vec<String> = parsed.iter().filter_map(|e| e.get("Title").cloned()).collect();+    assert_eq!(titles, vec!["Live".to_string()]);+}+ #[test] fn wrong_password_fails_to_import() {     let mut m = EntryMap::new();