Harden passphrase memory and migration paths
This commit is contained in:
@@ -40,6 +40,9 @@ Each bounded iteration must:
|
||||
conversion and persistence (26 X11-feature tests and Docker GTK/X11/package
|
||||
build, 2026-09-12).
|
||||
- [x] Create database, log, config, lock, and runtime directories with private permissions (mode probe and Docker build, 2026-09-10).
|
||||
- [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] 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).
|
||||
|
||||
7
Cargo.lock
generated
7
Cargo.lock
generated
@@ -168,6 +168,7 @@ dependencies = [
|
||||
"tracing-subscriber",
|
||||
"x11-clipboard",
|
||||
"x11rb",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1658,3 +1659,9 @@ dependencies = [
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zeroize"
|
||||
version = "1.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e"
|
||||
|
||||
@@ -19,6 +19,7 @@ serde = { version = "1.0", features = ["derive"] }
|
||||
sha2 = "0.10"
|
||||
thiserror = "2.0"
|
||||
toml = "0.8"
|
||||
zeroize = "1.8"
|
||||
tracing = "0.1"
|
||||
tracing-appender = "0.2"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt"] }
|
||||
|
||||
@@ -14,6 +14,7 @@ use gtk4::{
|
||||
Application, ApplicationWindow, Box as GtkBox, Button, Entry, Label, ListBox, ListBoxRow,
|
||||
Orientation, ResponseType, ScrolledWindow, TextView,
|
||||
};
|
||||
use zeroize::Zeroizing;
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
@@ -82,6 +83,7 @@ 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")?
|
||||
};
|
||||
drop(passphrase);
|
||||
let now = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
@@ -152,7 +154,7 @@ pub fn run(config: Config, instance: InstanceGuard, show_on_start: bool) -> Resu
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn prompt_for_passphrase() -> Result<String> {
|
||||
fn prompt_for_passphrase() -> Result<Zeroizing<String>> {
|
||||
let application = Application::new(Some("io.cliphoard.Cliphoard.Unlock"), Default::default());
|
||||
let passphrase = Rc::new(RefCell::new(None));
|
||||
let result = Rc::clone(&passphrase);
|
||||
@@ -201,7 +203,7 @@ fn prompt_for_passphrase() -> Result<String> {
|
||||
.borrow_mut()
|
||||
.take()
|
||||
.context("Cliphoard unlock was cancelled");
|
||||
result
|
||||
result.map(Zeroizing::new)
|
||||
}
|
||||
|
||||
fn confirm_plaintext_migration() -> Result<bool> {
|
||||
|
||||
@@ -45,6 +45,12 @@ impl Database {
|
||||
if !path.exists() {
|
||||
return Ok(false);
|
||||
}
|
||||
let metadata = std::fs::symlink_metadata(path)?;
|
||||
anyhow::ensure!(
|
||||
!metadata.file_type().is_symlink(),
|
||||
"refusing to inspect symlinked database {}",
|
||||
path.display()
|
||||
);
|
||||
let mut file = std::fs::File::open(path)
|
||||
.with_context(|| format!("failed to inspect database {}", path.display()))?;
|
||||
let mut header = [0; 16];
|
||||
@@ -59,6 +65,12 @@ impl Database {
|
||||
Self::is_plaintext(&path)?,
|
||||
"database is not plaintext SQLite"
|
||||
);
|
||||
let metadata = std::fs::symlink_metadata(&path)?;
|
||||
anyhow::ensure!(
|
||||
!metadata.file_type().is_symlink(),
|
||||
"refusing to migrate symlinked database {}",
|
||||
path.display()
|
||||
);
|
||||
let source = Connection::open(&path)
|
||||
.with_context(|| format!("failed to open plaintext history {}", path.display()))?;
|
||||
let mut statement = source.prepare(
|
||||
@@ -454,4 +466,18 @@ mod tests {
|
||||
let _ = std::fs::remove_file(&path);
|
||||
let _ = std::fs::remove_file(backup);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plaintext_inspection_refuses_symlinked_database() {
|
||||
let link =
|
||||
std::env::temp_dir().join(format!("cliphoard-plaintext-link-{}", std::process::id()));
|
||||
let target = link.with_extension("target");
|
||||
let _ = std::fs::remove_file(&link);
|
||||
let _ = std::fs::remove_file(&target);
|
||||
std::fs::write(&target, Database::SQLITE_HEADER).unwrap();
|
||||
std::os::unix::fs::symlink(&target, &link).unwrap();
|
||||
assert!(Database::is_plaintext(&link).is_err());
|
||||
let _ = std::fs::remove_file(&link);
|
||||
let _ = std::fs::remove_file(target);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user