From c7afd1ea752aeff0310ac7c6b78d091ac360c760 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 15 Nov 2026 15:38:57 +0100 Subject: 0.4.3: kill process groups, bound bash output, keep the key out of tool env - setsid-style process group kill on timeout and on Ctrl-C - 64 MiB RLIMIT_FSIZE so a runaway command cannot fill /tmp - OPENCODE_API_KEY removed from child environment - sessions 0600/0700, history 0600 and trimmed --- src/session.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/session.rs') diff --git a/src/session.rs b/src/session.rs index 9f2b699..f27a188 100644 --- a/src/session.rs +++ b/src/session.rs @@ -1,6 +1,8 @@ use std::fs::{File, OpenOptions}; use std::hash::{Hash, Hasher}; use std::io::{BufRead, BufReader, Read, Write}; +use std::os::unix::fs::PermissionsExt; +use std::path::Path; use std::path::PathBuf; use std::time::{SystemTime, UNIX_EPOCH}; @@ -41,6 +43,11 @@ pub fn sessions_dir() -> PathBuf { data_root().join("sessions") } +/// Sessions contain the whole conversation, so they are for this user only. +fn restrict(path: &Path, mode: u32) { + let _ = std::fs::set_permissions(path, std::fs::Permissions::from_mode(mode)); +} + pub struct Session { pub id: String, pub model: String, @@ -66,12 +73,15 @@ impl Session { pub fn create_as(id: String, model: &str, system: &Value) -> Result { let dir = sessions_dir(); std::fs::create_dir_all(&dir).map_err(|e| format!("{}: {e}", dir.display()))?; + restrict(&data_root(), 0o700); + restrict(&dir, 0o700); let path = dir.join(format!("{id}.jsonl")); let mut file = OpenOptions::new() .create_new(true) .append(true) .open(&path) .map_err(|e| format!("{}: {e}", path.display()))?; + restrict(&path, 0o600); let header = json!({ "t": "header", @@ -141,6 +151,8 @@ impl Session { .append(true) .open(&path) .map_err(|e| format!("{}: {e}", path.display()))?; + // Older builds created these 0644. + restrict(&path, 0o600); Ok(( Session { -- cgit v1.2.3