diff --git a/THREAT-MODEL.md b/THREAT-MODEL.md index 183763415..ade0c71da 100644 --- a/THREAT-MODEL.md +++ b/THREAT-MODEL.md @@ -228,7 +228,10 @@ provider (e.g. Ollama on `127.0.0.1`): then nothing leaves your machine ([ADR 0084](docs/adr/0084-red-risk-requires-confirm.md), §3). - **File reads and writes by the AI** appear in the ledger as path, size, SHA-256 and (for writes) backup path only — never the file content or a diff. Paths - are redacted like command text. A SHA-256 of very short or low-entropy + are redacted like command text. A write that failed after it reached the + target (or whose outcome is unknown) is recorded the same way, marked as + failed (the file may be partly overwritten), without hashes of the new + content. A SHA-256 of very short or low-entropy content (a PIN file, a single-token line) can be recovered by brute force, so the hash is not a secrecy boundary: the protection is the encrypted database, not the hash diff --git a/changelog.d/issue-1485-failed-file-write-record.md b/changelog.d/issue-1485-failed-file-write-record.md new file mode 100644 index 000000000..184def569 --- /dev/null +++ b/changelog.d/issue-1485-failed-file-write-record.md @@ -0,0 +1,2 @@ +### Fixed +- The activity record now notes an AI file write that failed after it started, since the file may be partly overwritten. diff --git a/crates/app-logic/src/orchestration/action_exec/tests_check_unavailable.rs b/crates/app-logic/src/orchestration/action_exec/tests_check_unavailable.rs index d98ceac2e..1608f4364 100644 --- a/crates/app-logic/src/orchestration/action_exec/tests_check_unavailable.rs +++ b/crates/app-logic/src/orchestration/action_exec/tests_check_unavailable.rs @@ -585,6 +585,7 @@ async fn test_ledger_redacts_fake_secret_in_file_paths_and_connection_detail() { }, LedgerEntryContent::FileWritten { path: "/srv/app?password=hunter2geheim".to_string(), + status: Default::default(), backup_path: None, bytes_before: None, bytes_after: Some(1), diff --git a/crates/app-logic/src/orchestration/action_exec/tests_file_ledger.rs b/crates/app-logic/src/orchestration/action_exec/tests_file_ledger.rs index deb91a480..fa871add9 100644 --- a/crates/app-logic/src/orchestration/action_exec/tests_file_ledger.rs +++ b/crates/app-logic/src/orchestration/action_exec/tests_file_ledger.rs @@ -169,6 +169,7 @@ async fn test_file_write_records_backup_and_both_hashes_without_content() { assert!(entries[0].meta.action_id.is_some()); let LedgerEntryContent::FileWritten { path: p, + status: _, backup_path, bytes_before, bytes_after, @@ -356,3 +357,208 @@ async fn test_failed_approved_file_write_records_decision_but_no_file_written() Some(LedgerDecisionOutcome::Confirmed) ); } + +fn failed_entry( + entries: &[persistence_sqlite::LedgerEntry], +) -> (&persistence_sqlite::LedgerEntry, &LedgerEntryContent) { + let e = entries + .iter() + .find(|e| matches!(e.content, LedgerEntryContent::FileWritten { .. })) + .unwrap_or_else(|| panic!("expected file_written: {entries:?}")); + (e, &e.content) +} + +#[tokio::test] +async fn test_write_failing_mid_stream_records_failed_file_written() { + let path = "/home/deploy/app.conf"; + let (entries, _t, _c) = run_write_all( + write_action(path, "NEW-MARKER-2 body"), + MockSshTransport::default(), + MockSftpSession::new() + .with_file(path, b"OLD-MARKER-1 body".to_vec()) + .with_partial_write_failure(path), + false, + true, + ) + .await; + let decision = entries + .iter() + .find(|e| decision_outcome(e) == Some(LedgerDecisionOutcome::Confirmed)) + .unwrap_or_else(|| panic!("expected decision: {entries:?}")); + let (written, content) = failed_entry(&entries); + assert_eq!(decision.meta.action_id, written.meta.action_id); + let LedgerEntryContent::FileWritten { + path: p, + status, + backup_path, + bytes_after, + sha256_after, + .. + } = content + else { + unreachable!() + }; + assert_eq!(p, path); + assert_eq!( + *status, + ssh_manager_core::audit::LedgerFileWriteStatus::Failed + ); + assert!(backup_path + .as_deref() + .unwrap() + .starts_with("/home/deploy/app.conf.smartssh-backup-")); + assert!(bytes_after.is_none() && sha256_after.is_none()); + let json = serde_json::to_string(content).unwrap(); + assert!(!json.contains("MARKER"), "no content in the record: {json}"); +} + +#[tokio::test] +async fn test_new_file_failing_before_open_records_no_file_written_entry() { + // The new target was never created (e.g. missing directory): no record. + let path = "/home/deploy/missing-dir/new.conf"; + let (entries, _t, _c) = run_write_all( + write_action(path, "neu"), + MockSshTransport::default(), + MockSftpSession::new().with_failing_open_for_write(path), + false, + true, + ) + .await; + assert!( + !entries + .iter() + .any(|e| matches!(e.content, LedgerEntryContent::FileWritten { .. })), + "{entries:?}" + ); +} + +#[tokio::test] +async fn test_new_file_failing_with_closed_session_records_failed_file_written() { + // The stat after the failure cannot tell whether the file was created + // (session closed): the possibly partly written file is recorded. + let path = "/home/deploy/new.conf"; + let (entries, _t, _c) = run_write_all( + write_action(path, "neu und lang"), + MockSshTransport::default(), + MockSftpSession::new() + .with_failing_open_for_write(path) + .with_session_drop_on_failed_write(), + false, + true, + ) + .await; + let (_, content) = failed_entry(&entries); + assert!(matches!( + content, + LedgerEntryContent::FileWritten { + status: ssh_manager_core::audit::LedgerFileWriteStatus::Failed, + .. + } + )); +} + +#[tokio::test] +async fn test_new_file_failing_mid_stream_records_failed_file_written() { + // A new file that exists after the failure was touched: recorded. + let path = "/home/deploy/new.conf"; + let (entries, _t, _c) = run_write_all( + write_action(path, "neu und lang"), + MockSshTransport::default(), + MockSftpSession::new().with_partial_write_failure(path), + false, + true, + ) + .await; + let (_, content) = failed_entry(&entries); + assert!(matches!( + content, + LedgerEntryContent::FileWritten { + status: ssh_manager_core::audit::LedgerFileWriteStatus::Failed, + .. + } + )); +} + +#[tokio::test] +async fn test_failed_file_write_path_is_redacted() { + let path = "/srv/app?password=hunter2geheim"; + let normalized = normalize_lexical_path(path); + let (entries, _t, _c) = run_write( + write_action(path, "x"), + MockSshTransport::default(), + MockSftpSession::new().with_partial_write_failure(normalized), + false, + true, + ) + .await; + let (_, content) = failed_entry(&entries); + let json = serde_json::to_string(content).unwrap(); + assert!(!json.contains("hunter2geheim"), "{json}"); +} + +#[tokio::test] +async fn test_backup_failure_records_no_file_written_entry() { + // The backup copy fails before the target is touched. + let path = "/home/deploy/app.conf"; + let backup_fail = MockSftpSession::new() + .with_file(path, b"alt".to_vec()) + .with_permission_denied(path); + let (entries, _t, _c) = run_write( + write_action(path, "neu"), + MockSshTransport::default().with_prefix_response( + "sudo -S cp -p ", + ssh_manager_core::ssh::CommandOutput { + stdout: Vec::new(), + stderr: b"cp: failed".to_vec(), + exit_code: Some(1), + truncated: false, + }, + ), + backup_fail, + true, + true, + ) + .await; + assert!(entries.is_empty(), "{entries:?}"); +} + +#[tokio::test] +async fn test_failed_sudo_install_records_failed_file_written_with_sudo() { + let path = "/etc/nginx/nginx.conf"; + let transport = MockSshTransport::default() + .with_prefix_response("sudo -S cp -p '/etc/nginx/nginx.conf' ", output("")) + .with_prefix_response( + "sudo -S install -m 644 ", + ssh_manager_core::ssh::CommandOutput { + stdout: Vec::new(), + stderr: b"install: failed".to_vec(), + exit_code: Some(1), + truncated: false, + }, + ); + let (entries, _t, _c) = run_write( + write_action(path, "neu"), + transport, + MockSftpSession::new() + .with_file(path, b"alt".to_vec()) + .with_permission_denied(path), + true, + true, + ) + .await; + let (_, content) = failed_entry(&entries); + let LedgerEntryContent::FileWritten { + status, + sudo, + backup_path, + .. + } = content + else { + unreachable!() + }; + assert_eq!( + *status, + ssh_manager_core::audit::LedgerFileWriteStatus::Failed + ); + assert!(*sudo && backup_path.is_some()); +} diff --git a/crates/app-logic/src/orchestration/chat_turn/ledger_redaction.rs b/crates/app-logic/src/orchestration/chat_turn/ledger_redaction.rs index e31342815..6869afe3d 100644 --- a/crates/app-logic/src/orchestration/chat_turn/ledger_redaction.rs +++ b/crates/app-logic/src/orchestration/chat_turn/ledger_redaction.rs @@ -41,6 +41,7 @@ pub(super) fn redact_ledger_entry_content( // Only the paths can carry a secret; sizes and hashes are not content. LedgerEntryContent::FileWritten { path, + status, backup_path, bytes_before, bytes_after, @@ -49,6 +50,7 @@ pub(super) fn redact_ledger_entry_content( sudo, } => LedgerEntryContent::FileWritten { path: redactor.redact_text(&path), + status, backup_path: backup_path.map(|b| redactor.redact_text(&b)), bytes_before, bytes_after, diff --git a/crates/app-logic/src/orchestration/remote_files.rs b/crates/app-logic/src/orchestration/remote_files.rs index 54d990db9..60f8c6c1c 100644 --- a/crates/app-logic/src/orchestration/remote_files.rs +++ b/crates/app-logic/src/orchestration/remote_files.rs @@ -8,7 +8,7 @@ use uuid::Uuid; use super::approval::ApprovedFileWrite; use ssh_manager_core::ai::{fence_untrusted, ChatMessage, MessageContent, Role, UntrustedKind}; -use ssh_manager_core::audit::{LedgerEntryContent, LedgerSource}; +use ssh_manager_core::audit::{LedgerEntryContent, LedgerFileWriteStatus, LedgerSource}; use ssh_manager_core::profiles::{AiAction, ProfileStore}; use ssh_manager_core::ssh::elevated::shell_single_quote; use ssh_manager_core::ssh::{CommandOutput, SshError}; @@ -46,6 +46,33 @@ struct WriteDone { sha256_before: Option, } +/// A failed write. `started` is true once the write to the target itself was +/// issued (direct SFTP write, or the privileged `install`), so the target may +/// be partly changed; failures before that (backup, temp file, permission +/// denied on open) leave it untouched. `backup_path` is set once the backup +/// exists. +struct WriteFailure { + error: SshError, + started: bool, + backup_path: Option, +} + +impl WriteFailure { + fn before_target(error: SshError) -> Self { + Self { + error, + started: false, + backup_path: None, + } + } +} + +impl From for WriteFailure { + fn from(error: SshError) -> Self { + Self::before_target(error) + } +} + /// Spec 0020, Abschnitt 3: öffnet die SFTP-Session der Session lazy (erst /// beim ersten Aufruf) und hält sie danach für die Dauer der Session offen /// (`session.sftp` bleibt `Some`, bis die Session selbst endet). Ein @@ -319,7 +346,7 @@ async fn write_via_sftp_with_backup( path: &str, content: &str, existed: bool, -) -> Result { +) -> Result { let backup_path = if existed { Some(backup_path_for(path)) } else { @@ -337,7 +364,16 @@ async fn write_via_sftp_with_backup( let mut guard = session.lock_sftp().await; let sftp = guard.sftp_or_err()?; - sftp.write_file(path, content.as_bytes()).await?; + if let Err(error) = sftp.write_file(path, content.as_bytes()).await { + // Permission denied is refused on open: the target is untouched (and + // the sudo fallback may follow). Any other error may be mid-stream. + let started = !matches!(error, SshError::SftpPermissionDenied(_)); + return Err(WriteFailure { + error, + started, + backup_path, + }); + } Ok(WriteDone { backup_path, @@ -390,7 +426,7 @@ async fn write_via_sudo_fallback( existed: bool, old_mode: Option, password: &secrecy::SecretString, -) -> Result { +) -> Result { let backup_path = if existed { Some(backup_path_for(path)) } else { @@ -453,13 +489,74 @@ async fn write_via_sudo_fallback( } } - install_result?; + // The `install` command is the write to the target; a non-zero exit may + // come after it began copying, so the target counts as possibly changed. + if let Err(error) = install_result { + return Err(WriteFailure { + error, + started: true, + backup_path, + }); + } Ok(WriteDone { backup_path, sha256_before, }) } +/// Activity record for a write that failed after it started (the target may be +/// partly overwritten). Writes nothing when the target was never touched. +/// No content, no hashes: nothing is known to have been written. +#[expect(clippy::too_many_arguments, reason = "one argument per input")] +async fn record_failed_write( + session: &Session, + ledger_source: LedgerSource, + path: &str, + bytes_before: Option, + existed: bool, + failure: &WriteFailure, + sudo: bool, + action_id: Uuid, +) { + if !failure.started { + return; + } + // A new file whose open failed (missing directory, wrong sudo password) + // was never touched: if the stat says it is missing, nothing was written + // and nothing is recorded. If the state cannot be established (session + // closed, permission denied, no channel) the file may be partly written, + // so the failed entry is kept. + if !existed { + let mut guard = session.lock_sftp().await; + if let Some(sftp) = guard.sftp() { + match sftp.stat(path).await { + Ok(_) + | Err( + ssh_manager_core::ssh::SshError::SessionClosed(_) + | ssh_manager_core::ssh::SshError::SftpPermissionDenied(_), + ) => {} + Err(_) => return, + } + } + } + write_ledger_entry_for_action( + session, + ledger_source, + LedgerEntryContent::FileWritten { + path: path.to_string(), + status: LedgerFileWriteStatus::Failed, + backup_path: failure.backup_path.clone(), + bytes_before, + bytes_after: None, + sha256_before: None, + sha256_after: None, + sudo, + }, + Some(action_id), + ) + .await; +} + /// Spec 0020, Abschnitt 4.2/4.3: kompletter Schreib-Ablauf — regulärer /// SFTP-Versuch zuerst, bei fehlenden Rechten (und **nur** dann) Sudo- /// Fallback, sofern für den Server ein Passwort hinterlegt ist. Ohne @@ -542,7 +639,10 @@ pub(crate) async fn execute_write_remote_file( let (done, used_sudo_password) = match regular { Ok(done) => (done, false), - Err(SshError::SftpPermissionDenied(_)) => { + Err(WriteFailure { + error: SshError::SftpPermissionDenied(_), + .. + }) => { // Spec 0068, Teil 3: Sudo-Fallback nur, wenn der Dialog ihn vorab // angekündigt hat — genau der im Event gesendete Wert // (Review-Fund: keine Neuberechnung, die auseinanderlaufen kann). @@ -581,7 +681,19 @@ pub(crate) async fn execute_write_remote_file( .await { Ok(done) => (done, true), - Err(err) => { + Err(failure) => { + record_failed_write( + session, + ledger_source, + &path, + bytes_before, + existed, + &failure, + true, + action_id, + ) + .await; + let err = failure.error; let code = err.code(); return emit_action_error( session, @@ -597,7 +709,19 @@ pub(crate) async fn execute_write_remote_file( } } } - Err(err) => { + Err(failure) => { + record_failed_write( + session, + ledger_source, + &path, + bytes_before, + existed, + &failure, + false, + action_id, + ) + .await; + let err = failure.error; let code = err.code(); return emit_action_error( session, @@ -622,6 +746,7 @@ pub(crate) async fn execute_write_remote_file( ledger_source, LedgerEntryContent::FileWritten { path: path.clone(), + status: LedgerFileWriteStatus::Completed, backup_path: backup_path.clone(), bytes_before, bytes_after: Some(wire_content.len() as u64), diff --git a/crates/core/src/audit/mod.rs b/crates/core/src/audit/mod.rs index f06d4c0bd..90a452052 100644 --- a/crates/core/src/audit/mod.rs +++ b/crates/core/src/audit/mod.rs @@ -126,12 +126,17 @@ pub enum LedgerEntryContent { bytes: Option, sha256: Option, }, - /// An AI file write (Spec 0057): written only when bytes were actually - /// written. Neither content nor diff is stored; `None` in a before/after + /// An AI file write (Spec 0057): written when the write succeeded, or with + /// status `Failed` when it failed after it had started. Neither content nor diff is stored; `None` in a before/after /// field means "not known" (e.g. a new file has no "before"; the old /// content of a file only readable with elevated rights is not read). FileWritten { path: String, + /// `Failed`: the write started and then failed, so the target may be + /// partly overwritten; the size/hash fields of such an entry are `None` + /// (nothing is known to have been written). + #[serde(default)] + status: LedgerFileWriteStatus, /// Server-side backup of the previous content, if one was made. backup_path: Option, bytes_before: Option, @@ -150,6 +155,17 @@ pub enum LedgerEntryContent { ActivityTick, } +/// Outcome of a [`LedgerEntryContent::FileWritten`] entry. +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] +pub enum LedgerFileWriteStatus { + /// The whole write succeeded. + #[default] + Completed, + /// The write reached the target and then failed; it may be partly changed. + Failed, +} + /// Kind of a [`LedgerEntryContent::Connection`] entry. #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] @@ -199,3 +215,36 @@ pub struct LedgerEntryMeta { #[serde(default)] pub rule_snapshot: Option, } + +#[cfg(test)] +mod tests { + use super::*; + + /// A `file_written` row stored before the `status` field existed (#1483) + /// still reads back as `Completed`, other fields unchanged. + #[test] + fn test_legacy_file_written_without_status_deserializes_as_completed() { + let json = r#"{"FileWritten":{"path":"/etc/a","backup_path":"/etc/a.bak","bytes_before":3,"bytes_after":5,"sha256_before":"aa","sha256_after":"bb","sudo":true}}"#; + let content: LedgerEntryContent = serde_json::from_str(json).unwrap(); + let LedgerEntryContent::FileWritten { + path, + status, + backup_path, + bytes_before, + bytes_after, + sha256_before, + sha256_after, + sudo, + } = content + else { + panic!("expected file_written"); + }; + assert_eq!(status, LedgerFileWriteStatus::Completed); + assert_eq!(path, "/etc/a"); + assert_eq!(backup_path.as_deref(), Some("/etc/a.bak")); + assert_eq!((bytes_before, bytes_after), (Some(3), Some(5))); + assert_eq!(sha256_before.as_deref(), Some("aa")); + assert_eq!(sha256_after.as_deref(), Some("bb")); + assert!(sudo); + } +} diff --git a/crates/core/src/ssh/mock.rs b/crates/core/src/ssh/mock.rs index 5002d1dfa..020f3e52d 100644 --- a/crates/core/src/ssh/mock.rs +++ b/crates/core/src/ssh/mock.rs @@ -50,6 +50,15 @@ struct Inner { /// 0020, Abschnitt 4.3, ohne einen echten privilegierten Zielpfad zu /// brauchen. permission_denied_paths: HashSet, + /// Paths whose `write_file` stores half of the content and then fails + /// (an SFTP error mid-stream). + partial_write_paths: HashSet, + /// Paths whose `write_file` fails before anything is stored. + failing_open_paths: HashSet, + /// A failing write also drops the session: that write fails with + /// `SessionClosed` and every later `stat` fails the same way. + drop_session_on_failed_write: bool, + session_dropped: bool, /// Issue #625: bietet der simulierte Server `posix-rename@openssh.com` an? posix_rename: bool, /// Issue #625: Quellpfade, bei denen `rename` scheitern soll. @@ -89,6 +98,29 @@ impl MockSftpSession { self } + /// `write_file` on `path` writes the first half of the content, then fails. + pub fn with_partial_write_failure(self, path: impl Into) -> Self { + lock_tolerating_poison(&self.inner) + .partial_write_paths + .insert(path.into()); + self + } + + /// `write_file` on `path` fails with a channel error before storing anything. + pub fn with_failing_open_for_write(self, path: impl Into) -> Self { + lock_tolerating_poison(&self.inner) + .failing_open_paths + .insert(path.into()); + self + } + + /// A failing `write_file` closes the session: it fails with + /// [`SshError::SessionClosed`] and later `stat` calls fail the same way. + pub fn with_session_drop_on_failed_write(self) -> Self { + lock_tolerating_poison(&self.inner).drop_session_on_failed_write = true; + self + } + /// Issue #625: der simulierte Server bietet `posix-rename@openssh.com` an. pub fn with_posix_rename(self) -> Self { lock_tolerating_poison(&self.inner).posix_rename = true; @@ -211,6 +243,28 @@ impl SftpSession for MockSftpSession { "keine Schreibrechte für {path}" ))); } + if inner.failing_open_paths.contains(path) { + if inner.drop_session_on_failed_write { + inner.session_dropped = true; + return Err(SshError::SessionClosed(format!("session closed: {path}"))); + } + return Err(SshError::ChannelError(format!( + "Öffnen von {path} fehlgeschlagen" + ))); + } + if inner.partial_write_paths.contains(path) { + inner.files.insert( + path.to_string(), + MockFile { + content: content[..content.len() / 2].to_vec(), + permissions: 0o644, + modified: Some(Utc::now()), + }, + ); + return Err(SshError::ChannelError(format!( + "Verbindung beim Schreiben von {path} abgebrochen" + ))); + } inner.files.insert( path.to_string(), MockFile { @@ -354,6 +408,9 @@ impl SftpSession for MockSftpSession { async fn stat(&mut self, path: &str) -> Result { let mut inner = lock_tolerating_poison(&self.inner); inner.calls.push(format!("stat {path}")); + if inner.session_dropped { + return Err(SshError::SessionClosed(format!("session closed: {path}"))); + } if inner.dirs.contains(path) { return Ok(RemoteEntry { name: path.rsplit('/').next().unwrap_or(path).to_string(), diff --git a/docs/adr/0160-activity-record-file-reads-and-writes.md b/docs/adr/0160-activity-record-file-reads-and-writes.md index 5c625b28e..1a87b86cd 100644 --- a/docs/adr/0160-activity-record-file-reads-and-writes.md +++ b/docs/adr/0160-activity-record-file-reads-and-writes.md @@ -15,7 +15,7 @@ ADR 0047 point 3 limited the ledger to `SuggestCommand`. A file read or write by | What is recorded for a read? | `file_read`: path, size in bytes, SHA-256 of the bytes read. | Enough to tell which version of a file the AI saw, without keeping the content. | | What is recorded for a write? | `file_written`: path, backup path or none, size and SHA-256 before and after, whether the sudo fallback was used. | Lets a reader tie a change to the backup and verify it later. | | Content or diff? | Never stored. | The record is not a copy of server data; the hashes suffice. | -| When is `file_written` written? | Only after the write succeeded. A rejected, blocked or failed write leaves no `file_written` entry. | "Written" must mean bytes were written. A failed write is visible as the action error in the chat. | +| When is `file_written` written? | After the write succeeded, or with `status: failed` when it failed after it started (issue #1485). A rejected or blocked write, or one that failed before the target was touched (permission denied, backup or temp-file failure), leaves no entry. | A mid-stream error can leave the target partly overwritten; the record must say so. "Started" means: the direct SFTP write to the target was issued and failed with anything but permission denied (refused on open), or the privileged `install` exited non-zero. A failed `install` also covers a wrong sudo password, which cannot be told apart from a copy error; the entry therefore says "may be changed". For an existing file a wrong sudo password fails the privileged backup `cp` first, so no entry results. For a new file, after any such failure the target is checked once more: if the stat says it does not exist, nothing was touched and no entry is written; if the stat itself fails with a closed session or permission denied, the state is unknown and the failed entry is written. The shape is a `status` field on `FileWritten` (default `completed` for old rows), not a new entry kind, so readers keep one kind. A failed entry has no after-size or hash and no content. | | "Before" values | Size from the stat before the write; hash from the content read for the backup. On the sudo path the old content is read over SFTP once more for the hash; it is absent only when that read itself is denied or fails (size still recorded). A new file has no "before". | No privileged read is added; the extra read on the sudo path is an ordinary SFTP read. | | "After" values | Computed over the bytes sent to the server (after the edition's outgoing transform). | These are the bytes that were written. | | Keep the hashes? | Yes. The hashes stay, although the SHA-256 of very short or low-entropy content can be guessed by brute force. | They are needed to prove what changed and which version the AI saw. The protection for them is the encrypted database, not the hash; the threat model says so. | diff --git a/docs/specs/0057-rich-session-model.md b/docs/specs/0057-rich-session-model.md index cd1a914d0..5b3aec92a 100644 --- a/docs/specs/0057-rich-session-model.md +++ b/docs/specs/0057-rich-session-model.md @@ -63,8 +63,19 @@ Typen: - **Datei geschrieben** — Pfad, Pfad der Sicherungskopie, Größe und SHA-256 vorher/nachher sowie ob erhöhte Rechte (Sudo) genutzt wurden; nie Inhalt und nie ein Diff. Der „vorher"-Hash fehlt nur, wenn die alte Datei nicht - lesbar war oder neu angelegt wurde. Ein abgelehnter oder fehlgeschlagener - Schreibvorgang erzeugt keinen „Datei geschrieben"-Eintrag; die + lesbar war oder neu angelegt wurde. Ein abgelehnter Schreibvorgang oder einer, + der scheitert, bevor die Zieldatei angefasst wurde (Zugriff verweigert, + Sicherungskopie fehlgeschlagen), erzeugt keinen „Datei geschrieben"-Eintrag. + Das gilt auch für eine neue Datei, die nach dem Fehlschlag weiterhin nicht + existiert (z. B. fehlendes Verzeichnis, falsches Sudo-Passwort). Lässt sich + nach dem Fehlschlag nicht feststellen, ob die neue Datei angelegt wurde + (Sitzung geschlossen, Zugriff auf das Verzeichnis verweigert), steht der + Eintrag „fehlgeschlagen“, weil sie teilweise geschrieben sein kann. + Scheitert der Schreibvorgang, nachdem er die Zieldatei erreicht hat (z. B. + Abbruch mitten im Übertragen, fehlgeschlagener Sudo-Kopierschritt), steht ein + „Datei geschrieben"-Eintrag mit Status „fehlgeschlagen" im Ledger: Pfad, + Pfad der Sicherungskopie und Aktions-ID, ohne Größen-/Hash-Angaben „nachher", + nie Inhalt oder Diff; die Zieldatei kann teilweise überschrieben sein. Die **Entscheidung** (bestätigt, abgelehnt, automatisch freigegeben) steht wie bei Kommandos im Ledger und ist über dieselbe Aktions-ID mit dem „Datei geschrieben"-Eintrag verknüpft.