From a869cd4c7ba5e4744a09e53a011018c5d293a177 Mon Sep 17 00:00:00 2001 From: Mike Plotz Sage Date: Sat, 14 Feb 2026 16:04:04 -0800 Subject: [PATCH] fix: move unix socket from /tmp/ to ~/.wake/sockets/ Sockets in world-writable /tmp/ are vulnerable to symlink attacks, path prediction, and denial of service. Using a user-owned directory under ~/.wake/ eliminates these risks. Co-Authored-By: Claude Opus 4.6 --- README.md | 2 +- crates/wake-cli/Cargo.toml | 1 + crates/wake-cli/src/commands/shell.rs | 10 +++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b0b5925..eeac4ae 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,7 @@ cargo build --release --features metal # Apple Silicon │ │ │ ┌───────────┐ ┌─────────────┐ ┌──────────────────────┐ │ │ │ Your │ pty │ Shell │ hook │ Unix Socket │ │ -│ │ Terminal │◄─────►│ (zsh/bash) │─────►│ /tmp/wake-*.sock │ │ +│ │ Terminal │◄─────►│ (zsh/bash) │─────►│ ~/.wake/sockets/* │ │ │ └───────────┘ └─────────────┘ └──────────┬───────────┘ │ │ │ │ │ │ │ │ │ stdout │ cmd events │ diff --git a/crates/wake-cli/Cargo.toml b/crates/wake-cli/Cargo.toml index c8f3782..a8baa49 100644 --- a/crates/wake-cli/Cargo.toml +++ b/crates/wake-cli/Cargo.toml @@ -24,6 +24,7 @@ chrono.workspace = true signal-hook.workspace = true signal-hook-tokio.workspace = true anyhow.workspace = true +dirs.workspace = true term_size.workspace = true libc.workspace = true diff --git a/crates/wake-cli/src/commands/shell.rs b/crates/wake-cli/src/commands/shell.rs index 89ac276..847bf1a 100644 --- a/crates/wake-cli/src/commands/shell.rs +++ b/crates/wake-cli/src/commands/shell.rs @@ -33,7 +33,15 @@ struct SessionState { pub async fn run() -> Result<()> { let session_id = uuid::Uuid::new_v4().to_string(); - let socket_path = format!("/tmp/wake-{session_id}.sock"); + + // Use ~/.wake/sockets/ instead of /tmp/ to avoid world-writable directory risks + let socket_dir = dirs::home_dir() + .context("Could not determine home directory")? + .join(".wake") + .join("sockets"); + std::fs::create_dir_all(&socket_dir).context("Failed to create socket directory")?; + let socket_path = socket_dir.join(format!("wake-{session_id}.sock")); + let socket_path = socket_path.to_string_lossy().to_string(); // Clean up any stale socket let _ = std::fs::remove_file(&socket_path);