Add confirmed plaintext backup cleanup

This commit is contained in:
2026-09-12 17:18:19 +02:00
parent c6d84f9d30
commit 224a048f85
4 changed files with 70 additions and 3 deletions

View File

@@ -43,6 +43,9 @@ Each bounded iteration must:
- [x] Wrap the GUI passphrase in zeroizing memory and drop it after SQLCipher
unlock; reject symlinked database inspection/migration (32 GUI-feature tests
and GUI build, 2026-09-12).
- [x] Offer explicit cleanup of retained plaintext migration backups, while
warning that filesystem snapshots and external backups are outside its scope
(32 GUI-feature tests and GUI build, 2026-09-12).
- [x] Handle pre-existing overly-permissive database/log permissions safely (existing database and date-suffixed log regression tests, 17 tests and Docker build, 2026-09-10).
- [x] Add tests/probes for file modes under permissive umasks (database regression test plus runtime probe, 2026-09-10).
- [x] Confirm no normal log path emits clipboard contents (audited all `tracing` call sites; errors carry operation context only, 2026-09-10).

View File

@@ -113,6 +113,8 @@ Runtime files follow XDG conventions:
On first start, Cliphoard asks for a passphrase. The history database is
encrypted with SQLCipher and the passphrase is never stored. If an older
plaintext history is found, Cliphoard asks before migrating it and keeps the
original as a `.plaintext-backup` until you remove that backup yourself.
original as a `.plaintext-backup`, then offers to remove that plaintext backup.
Removing it deletes the file entry; it cannot erase copies already made by
backups, snapshots, or the filesystem.
The full product contract is in [.agents/BIBLE.md](.agents/BIBLE.md).

View File

@@ -73,7 +73,8 @@ const HELP_ICON: &str = "❓";
pub fn run(config: Config, instance: InstanceGuard, show_on_start: bool) -> Result<()> {
let passphrase = prompt_for_passphrase()?;
let database_path = Database::default_path();
let database = if Database::is_plaintext(&database_path)? {
let migrated = Database::is_plaintext(&database_path)?;
let database = if migrated {
if !confirm_plaintext_migration()? {
anyhow::bail!("plaintext history migration was declined")
}
@@ -83,6 +84,11 @@ pub fn run(config: Config, instance: InstanceGuard, show_on_start: bool) -> Resu
Database::open_encrypted(&database_path, &passphrase)
.context("could not unlock Cliphoard history; check the passphrase")?
};
if migrated && confirm_plaintext_cleanup()? {
if let Err(error) = Database::remove_plaintext_backups(&database_path) {
tracing::error!(%error, "failed to remove plaintext migration backup");
}
}
drop(passphrase);
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
@@ -236,6 +242,36 @@ fn confirm_plaintext_migration() -> Result<bool> {
Ok(result)
}
fn confirm_plaintext_cleanup() -> Result<bool> {
let application = Application::new(Some("io.cliphoard.Cliphoard.Cleanup"), Default::default());
let remove = Rc::new(RefCell::new(false));
let result = Rc::clone(&remove);
application.connect_activate(move |application| {
let dialog = gtk4::Dialog::builder()
.application(application)
.title("Remove plaintext backup?")
.modal(true)
.default_width(520)
.build();
dialog.content_area().append(&Label::new(Some(
"The encrypted history is ready. Remove the retained plaintext migration backup now? This removes the file from disk but cannot erase copies in backups or snapshots.",
)));
dialog.add_button("Keep backup", ResponseType::Cancel);
dialog.add_button("Remove plaintext backup", ResponseType::Accept);
let result_for_response = Rc::clone(&result);
let application_for_response = application.clone();
dialog.connect_response(move |dialog, response| {
*result_for_response.borrow_mut() = response == ResponseType::Accept;
dialog.close();
application_for_response.quit();
});
dialog.present();
});
application.run_with_args(&["cliphoard-cleanup"]);
let result = *remove.borrow();
Ok(result)
}
fn build_window(
application: &Application,
config: &Config,

View File

@@ -125,6 +125,31 @@ impl Database {
Self::open_encrypted(path, passphrase)
}
pub fn remove_plaintext_backups(path: impl AsRef<Path>) -> Result<usize> {
let path = path.as_ref();
let parent = path
.parent()
.context("database path has no parent directory")?;
let filename = path
.file_name()
.context("database path has no filename")?
.to_string_lossy();
let prefix = format!("{filename}.plaintext-backup");
let mut removed = 0;
for entry in std::fs::read_dir(parent)? {
let entry = entry?;
let name = entry.file_name();
let name = name.to_string_lossy();
if (name == prefix || name.starts_with(&format!("{prefix}.")))
&& entry.file_type()?.is_file()
{
std::fs::remove_file(entry.path())?;
removed += 1;
}
}
Ok(removed)
}
fn open_internal(path: impl AsRef<Path>, passphrase: Option<&str>) -> Result<Self> {
let path = path.as_ref().to_path_buf();
if let Ok(metadata) = std::fs::symlink_metadata(&path) {
@@ -460,8 +485,9 @@ mod tests {
assert!(!Database::is_plaintext(&path).unwrap());
let backup = path.with_extension("db.plaintext-backup");
assert!(backup.exists());
assert_eq!(Database::remove_plaintext_backups(&path).unwrap(), 1);
assert!(!backup.exists());
let _ = std::fs::remove_file(&path);
let _ = std::fs::remove_file(backup);
}
#[test]