From b196b6876315434cb86ab4ad87482080c16c6e06 Mon Sep 17 00:00:00 2001 From: Cuihtlauac ALVARADO Date: Sat, 21 Nov 2026 10:46:02 +0100 Subject: [PATCH 1/5] fix(executor): spawn the binary the Resolves: line shows (backport of #80) The prompt resolved argv[0] on the daemon's PATH while the executor spawned the bare name with a cleared environment, so the child looked it up again on a different PATH (login PATH, sudo's secure_path, sh for pkexec pipelines). A daemon started from a dev shell could show one file and run another. Resolve argv[0] once with executor::resolve_command (child's PATH; names with '/' relative to the child cwd '/'), display that in the TUI and GUI, and spawn it on every path: directly with the requested argv[0] kept, after sudo/pkexec, and in the pkexec sh -c string. Unresolved names are refused with "command not found" before any pipeline stage spawns. Re-applied by hand to the 1.2 pipeline executor: main's #80 targets the structured-plan executor and does not cherry-pick onto v1.2.1. Fixes #62. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Cuihtlauac ALVARADO --- changelog.md | 27 ++++++++ docs/security.md | 12 +++- src/executor.rs | 167 +++++++++++++++++++++++++++++++++++++++++++---- src/gui.rs | 15 +++-- src/tui.rs | 6 +- tests/exec.rs | 31 +++++++++ 6 files changed, 237 insertions(+), 21 deletions(-) diff --git a/changelog.md b/changelog.md index 5750eca..06556c6 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,33 @@ Most recent at top. See [docs/formalisation-roadmap.md](docs/formalisation-roadmap.md) for the assurance-ladder context behind the security-formalisation entries. +## Unreleased (1.2.2) — the `Resolves:` line names the binary that actually runs (#62, backport of #80) + +The prompt resolved `argv[0]` on the daemon's own PATH, but the executor +spawned the bare name with a cleared environment, so the child searched the +default login PATH (sudo searched its `secure_path`, pkexec's `sh -c` the login +PATH). A daemon started from a dev shell (Nix, virtualenv, `~/.local/bin`) +could show one file and run another, or show a file and then fail with ENOENT. + +`executor::resolve_command` now resolves argv[0] on the child's PATH, and a +name containing `/` against the child's working directory `/`. The TUI and GUI +prompts display that result, and every spawn path uses it: directly (keeping +the requested `argv[0]`), as the program after `sudo` / `pkexec`, and in the +multi-stage pkexec `sh -c` string. A name that does not resolve is refused with +`command not found: ` instead of being looked up a second time; in a +pipeline, before any stage is spawned. The GUI dialog now also shows +`(not found in PATH)`. As in 1.2.1, the TUI shows the `Resolves:` line for the +first stage and a warning for later stages that do not resolve. + +Behaviour change: a privileged command found only on sudo's `secure_path` (e.g. +`/snap/bin`) but not on the default login PATH is now refused, where it +previously ran under a mismatched prompt. + +This re-applies the fix from main (#80) to the 1.2 pipeline executor; the code +differs because 1.2 predates structured plans. Regressions: unit tests in +`executor` and `exec_direct_spawns_resolved_path_keeping_argv0` in +`tests/exec.rs`. + ## v1.2.1 — 2026-11-18 (security release) A patch release on top of v1.2.0 with two security fixes and nothing else: diff --git a/docs/security.md b/docs/security.md index c103290..5bb79c1 100644 --- a/docs/security.md +++ b/docs/security.md @@ -49,4 +49,14 @@ PATH-found file is itself a symlink), so a same-UID adversary who substitutes relying on a PATH search or passing the absolute path directly. If `canonicalize` fails (broken symlink, EACCES) the prompt says so explicitly rather than silently displaying the as-found name. If argv[0] is not found in -PATH, the prompt shows `(not found in PATH)` as a warning. +PATH, the prompt shows `(not found in PATH)` as a warning, and the stage is +refused at spawn. + +argv[0] is resolved **once**, the way the child would see it: a bare name is +searched on the child's PATH (the default login PATH, which no request can +change), never on the daemon's own PATH; a name containing `/` is taken +relative to the child's working directory, `/`. The executor then spawns that +resolved path, directly or as the program after `sudo` / `pkexec` (and in the +`sh -c` string of a multi-stage pkexec pipeline), so neither `Command`, sudo's +`secure_path`, nor `sh` performs a second lookup that could pick a different +file than the prompt showed (issue #62). diff --git a/src/executor.rs b/src/executor.rs index c6e9128..e26decf 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -112,7 +112,9 @@ pub fn apply_login_env_defaults(env: &mut HashMap) { } } -/// Resolve a command name to an absolute path by searching PATH. +/// Resolve a command name to an absolute path by searching the **daemon's** +/// PATH. Only for the daemon's own helpers (zenity, kdialog), never for a +/// requested command — see [`resolve_command`]. pub fn which(name: &str) -> Option { if name.contains('/') { let p = PathBuf::from(name); @@ -121,8 +123,12 @@ pub fn which(name: &str) -> Option { } return None; } - let path_var = std::env::var("PATH").unwrap_or_default(); - for dir in path_var.split(':') { + search_path(name, &std::env::var("PATH").unwrap_or_default()) +} + +/// First executable regular file named `name` in the `:`-separated `path_list`. +fn search_path(name: &str, path_list: &str) -> Option { + for dir in path_list.split(':') { let candidate = Path::new(dir).join(name); if let Ok(meta) = candidate.metadata() { if meta.is_file() && (meta.permissions().mode() & 0o111 != 0) { @@ -133,6 +139,44 @@ pub fn which(name: &str) -> Option { None } +/// Resolve a requested `argv[0]` the way the child sees it (issue #62): a bare +/// name is searched on the child's PATH — the default login PATH, which no +/// request can change — never on the daemon's own PATH; a name containing `/` +/// is taken relative to the child's working directory, `/`. The prompt shows +/// this result and the executor spawns it, so neither `Command`, sudo's +/// `secure_path`, nor `sh` performs a second lookup that could pick a +/// different file than the one the human approved. +pub fn resolve_command(name: &str) -> Option { + if name.contains('/') { + let p = Path::new("/").join(name); + return p.is_file().then_some(p); + } + search_path(name, DEFAULT_LOGIN_PATH) +} + +/// `argv` with `argv[0]` replaced by its [`resolve_command`] result, for the +/// sudo / pkexec paths that take the program as an argument. A name that does +/// not resolve is refused instead of being looked up again by sudo or `sh`. +fn resolved_argv(argv: &[String]) -> Result, String> { + let bin = resolve_command(&argv[0]) + .ok_or_else(|| format!("command not found: {}", argv[0]))?; + let mut out = Vec::with_capacity(argv.len()); + out.push(bin.to_string_lossy().into_owned()); + out.extend(argv[1..].iter().cloned()); + Ok(out) +} + +/// A `Command` that spawns the resolved `argv[0]` directly, keeping the +/// requested name as the child's `argv[0]` (what `ps` and the program see). +fn direct_command(argv: &[String]) -> Result { + let bin = resolve_command(&argv[0]) + .ok_or_else(|| format!("command not found: {}", argv[0]))?; + let mut cmd = Command::new(bin); + cmd.arg0(&argv[0]); + cmd.args(&argv[1..]); + Ok(cmd) +} + /// Execute a pipeline via pkexec (local/graphical mode). /// For multi-stage pipelines, wraps in `pkexec sh -c 'cmd1 | cmd2 | ...'`. pub fn exec_pkexec( @@ -144,8 +188,15 @@ pub fn exec_pkexec( return exec_pkexec_stage(&req.pipeline[0], env, &req.id, tty_lock); } - // Multi-stage: wrap entire pipeline in sh -c via pkexec - let shell_cmd = pipeline_to_shell(&req.pipeline, env); + // Multi-stage: wrap entire pipeline in sh -c via pkexec, each stage's + // program spelled as its resolved absolute path so `sh` does no lookup. + let resolved: Result>, String> = + req.pipeline.iter().map(|argv| resolved_argv(argv)).collect(); + let resolved = match resolved { + Ok(r) => r, + Err(e) => return Response::error(&req.id, &e), + }; + let shell_cmd = pipeline_to_shell(&resolved, env); let mut cmd = Command::new("pkexec"); cmd.args(["sh", "-c", &shell_cmd]); cmd.current_dir("/"); @@ -199,8 +250,12 @@ fn exec_pkexec_stage( id: &str, tty_lock: &Mutex<()>, ) -> Response { + let argv = match resolved_argv(argv) { + Ok(a) => a, + Err(e) => return Response::error(id, &e), + }; let mut cmd = Command::new("pkexec"); - for arg in argv { + for arg in &argv { cmd.arg(arg); } cmd.current_dir("/"); @@ -230,11 +285,15 @@ fn exec_sudo_stage( id: &str, tty_lock: &Mutex<()>, ) -> Response { + let argv = match resolved_argv(argv) { + Ok(a) => a, + Err(e) => return Response::error(id, &e), + }; let mut cmd = Command::new("sudo"); for (k, v) in env { cmd.arg(format!("{k}={v}")); } - for arg in argv { + for arg in &argv { cmd.arg(arg); } cmd.current_dir("/"); @@ -254,8 +313,10 @@ fn exec_direct_stage( id: &str, forward_agent: bool, ) -> Response { - let mut cmd = Command::new(&argv[0]); - cmd.args(&argv[1..]); + let mut cmd = match direct_command(argv) { + Ok(c) => c, + Err(e) => return Response::error(id, &e), + }; cmd.current_dir("/"); cmd.stdin(Stdio::null()); cmd.stdout(Stdio::piped()); @@ -384,10 +445,19 @@ fn exec_pipeline( let n = req.pipeline.len(); assert!(n >= 2); + // Resolve every stage before spawning any, so an unresolvable stage + // refuses the whole pipeline instead of leaving earlier stages running. + let resolved: Result>, String> = + req.pipeline.iter().map(|argv| resolved_argv(argv)).collect(); + let resolved = match resolved { + Ok(r) => r, + Err(e) => return Response::error(&req.id, &e), + }; + let mut children: Vec = Vec::with_capacity(n); let mut prev_stdout: Option = None; - for (i, argv) in req.pipeline.iter().enumerate() { + for (i, (argv, bin_argv)) in req.pipeline.iter().zip(&resolved).enumerate() { let is_first = i == 0; let is_last = i == n - 1; @@ -397,13 +467,14 @@ fn exec_pipeline( for (k, v) in env { c.arg(format!("{k}={v}")); } - for arg in argv { + for arg in bin_argv { c.arg(arg); } c } EscalationMode::Direct => { - let mut c = Command::new(&argv[0]); + let mut c = Command::new(&bin_argv[0]); + c.arg0(&argv[0]); c.args(&argv[1..]); c.env_clear(); for (k, v) in env { @@ -783,6 +854,78 @@ mod tests { use crate::prop::Rng; use std::time::Duration; + // === Issue #62: argv[0] is resolved once, on the child's PATH. + + fn exe(dir: &Path, name: &str) -> PathBuf { + let p = dir.join(name); + std::fs::write(&p, "#!/bin/sh\n").unwrap(); + std::fs::set_permissions(&p, std::fs::Permissions::from_mode(0o755)).unwrap(); + p + } + + #[test] + fn search_path_takes_first_executable_in_order() { + let a = tempfile::tempdir().unwrap(); + let b = tempfile::tempdir().unwrap(); + // Non-executable file in the first dir is skipped. + std::fs::write(a.path().join("tool"), "x").unwrap(); + let want = exe(b.path(), "tool"); + let list = format!("{}:{}", a.path().display(), b.path().display()); + assert_eq!(search_path("tool", &list), Some(want)); + exe(a.path(), "tool"); + assert_eq!(search_path("tool", &list), Some(a.path().join("tool"))); + } + + #[test] + fn resolve_command_uses_child_path_not_daemon_path() { + // A bare name resolves inside DEFAULT_LOGIN_PATH, whatever the + // daemon's own PATH says; a name found only elsewhere does not resolve. + let sh = resolve_command("sh").expect("sh on the login PATH"); + assert!( + DEFAULT_LOGIN_PATH.split(':').any(|d| sh.parent() == Some(Path::new(d))), + "{sh:?} not under {DEFAULT_LOGIN_PATH}" + ); + let only_here = tempfile::tempdir().unwrap(); + exe(only_here.path(), "sudo-proxy-only-here-62"); + assert_eq!(resolve_command("sudo-proxy-only-here-62"), None); + } + + #[test] + fn resolve_command_takes_slash_names_relative_to_child_cwd() { + // The child runs in `/`, so `bin/sh` means `/bin/sh`, not + // `/bin/sh`. + let expect = Path::new("/bin/sh").is_file().then(|| PathBuf::from("/bin/sh")); + assert_eq!(resolve_command("bin/sh"), expect); + let tmp = tempfile::tempdir().unwrap(); + let abs = exe(tmp.path(), "tool"); + assert_eq!(resolve_command(abs.to_str().unwrap()), Some(abs)); + } + + #[test] + fn unresolved_stage_is_refused_not_looked_up_again() { + let argv = vec!["sudo-proxy-no-such-cmd-62".to_string(), "x".into()]; + assert_eq!( + resolved_argv(&argv).unwrap_err(), + "command not found: sudo-proxy-no-such-cmd-62" + ); + assert!(direct_command(&argv).is_err()); + let ok = resolved_argv(&["sh".to_string(), "-c".into(), "true".into()]).unwrap(); + assert!(ok[0].starts_with('/'), "{ok:?}"); + assert_eq!(&ok[1..], ["-c", "true"]); + } + + #[test] + fn pkexec_shell_string_spells_resolved_paths() { + let r: Vec> = [vec!["sh", "-c", "true"], vec!["cat"]] + .iter() + .map(|a| resolved_argv(&a.iter().map(|s| s.to_string()).collect::>()).unwrap()) + .collect(); + let s = pipeline_to_shell(&r, &HashMap::new()); + for stage in s.split(" | ") { + assert!(stage.starts_with('/'), "stage not absolute: {stage:?} in {s:?}"); + } + } + fn pid_alive(pid: u32) -> bool { unsafe { libc::kill(pid as libc::pid_t, 0) == 0 } } diff --git a/src/gui.rs b/src/gui.rs index 282525f..bf99bd3 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -2,7 +2,7 @@ use std::io; use std::process::{Command, Stdio}; use std::time::Duration; -use crate::executor::which; +use crate::executor::{resolve_command, which}; use crate::protocol::ValidatedRequest; use crate::tui::{self, pipeline_join, Prompter, PromptResult}; @@ -58,11 +58,16 @@ fn format_prompt_text(req: &ValidatedRequest) -> String { lines.push(format!("Command: {}", pipeline_join(&req.pipeline))); if let Some(first_argv) = req.pipeline.first() { if let Some(cmd_name) = first_argv.first() { - if let Some(resolved) = which(cmd_name) { - let resolved_str = resolved.display().to_string(); - if resolved_str != *cmd_name { - lines.push(format!("Resolves: {}", resolved_str)); + // Same resolution the executor spawns (issue #62), not the + // daemon's PATH. + match resolve_command(cmd_name) { + Some(resolved) => { + let resolved_str = resolved.display().to_string(); + if resolved_str != *cmd_name { + lines.push(format!("Resolves: {}", resolved_str)); + } } + None => lines.push("Resolves: (not found in PATH)".to_string()), } } } diff --git a/src/tui.rs b/src/tui.rs index e3168c2..e8af694 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -5,7 +5,7 @@ use std::time::Duration; use base64::engine::general_purpose::STANDARD as B64; use base64::Engine; -use crate::executor::which; +use crate::executor::resolve_command; use crate::protocol::{Response, Status, ValidatedRequest}; /// Join argv into a shell-like display string, quoting args that contain spaces. @@ -205,7 +205,7 @@ pub fn prompt_tty( // Warn if later stages have commands not in PATH for argv in req.pipeline.iter().skip(1) { if let Some(cmd_name) = argv.first() { - if which(cmd_name).is_none() { + if resolve_command(cmd_name).is_none() { writeln!( tty_w, "Warning: {bold}{cmd_name}{reset} not found in PATH" @@ -280,7 +280,7 @@ pub fn prompt_tty( /// having verified the target. fn write_resolves_line(w: &mut W, cmd_name: &str, style: &Style) -> io::Result<()> { let Style { bold, dim, reset } = *style; - let resolved = match which(cmd_name) { + let resolved = match resolve_command(cmd_name) { Some(p) => p, None => { return writeln!(w, "Resolves: {bold}(not found in PATH){reset}"); diff --git a/tests/exec.rs b/tests/exec.rs index 2bcd3a5..a4cf16d 100644 --- a/tests/exec.rs +++ b/tests/exec.rs @@ -237,3 +237,34 @@ impl Drop for EnvRestore { } } } + +/// Issue #62: the child is spawned from the resolved path but keeps the +/// requested `argv[0]`, and a name that does not resolve on the child's PATH is +/// refused instead of being looked up again. +#[test] +fn exec_direct_spawns_resolved_path_keeping_argv0() { + let resp = exec_direct(&make_req(vec![vec!["cat", "/proc/self/cmdline"]]), &login_env()); + assert_eq!(resp.status, Status::Ok, "got {:?}", resp); + let out = common::b64_decode(resp.stdout.as_deref().unwrap_or("")); + assert!(out.starts_with(b"cat\0"), "argv[0] not preserved: {:?}", String::from_utf8_lossy(&out)); + + let resp = exec_direct(&make_req(vec![vec!["sudo-proxy-no-such-cmd-62"]]), &login_env()); + assert_eq!(resp.status, Status::Error); + assert!( + resp.message.as_deref().unwrap_or("").contains("command not found: sudo-proxy-no-such-cmd-62"), + "got {:?}", + resp + ); + + let resp = exec_direct( + &make_req(vec![vec!["echo", "hi"], vec!["sudo-proxy-no-such-cmd-62"]]), + &login_env(), + ); + assert_eq!(resp.status, Status::Error, "a pipeline with an unresolved stage must be refused"); +} + +fn login_env() -> HashMap { + let mut env = HashMap::new(); + apply_login_env_defaults(&mut env); + env +} From 13a5bd25a692a41867a51ff312b318c11e3f46d5 Mon Sep 17 00:00:00 2001 From: Cuihtlauac ALVARADO Date: Sat, 21 Nov 2026 18:04:02 +0100 Subject: [PATCH 2/5] fix(security): refuse approval terminals other processes can type into GHSA-cpmp-67wf-gwmx. The daemon approves by reading one key from its terminal and cannot tell a key typed by the human from one injected by a same-UID process, and the usual requester (an AI agent) has a same-UID shell. Under tmux/screen, kitty/wezterm/Konsole remote control, or X11 it could answer its own privileged prompt. - New ttyguard module: detect multiplexers, remote-control emulators, VS Code / Emacs terminals and X11-without-Wayland from the environment. The daemon refuses to start in such a terminal unless started with --allow-injectable-tty, which adds a warning line to every prompt. No hosts.json equivalent: an agent can write that file and restart the daemon via MCP. Skipped under --pkexec. Legacy TIOCSTI is a warning. - --host checks the local terminal before ssh and forwards the override. - Unprivileged children run in their own session (setsid), so they have no controlling terminal and cannot TIOCSTI into a later prompt. - sudo-proxy-mcp scrubs the launcher's terminal variables from the window it spawns, holds the window open on refusal, and explains the failure. - Threat model (B3 row, leaf 3.5, residuals), assurance-case A1, user docs. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Cuihtlauac ALVARADO --- README.md | 4 + changelog.md | 36 +++++ docs/assurance-case.md | 2 +- docs/install.md | 4 + docs/security.md | 27 +++- docs/threat-model.md | 21 ++- docs/usage.md | 21 +++ src/bin/sudo-proxy.rs | 72 ++++++++- src/executor.rs | 36 +++-- src/lib.rs | 1 + src/mcp.rs | 25 +++- src/ttyguard.rs | 331 +++++++++++++++++++++++++++++++++++++++++ src/tui.rs | 47 ++++++ tests/cli.rs | 101 +++++++++++++ tests/exec.rs | 17 +++ 15 files changed, 726 insertions(+), 19 deletions(-) create mode 100644 src/ttyguard.rs diff --git a/README.md b/README.md index dfa5d6d..0e9a2e6 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,10 @@ key ID `A6F84B53410B83FB`) before installing; a missing or bad signature aborts the install. Prefer `cargo install` if you'd rather build from source. +The daemon must run in a terminal window that no other process can type into: +outside tmux/screen, on Wayland. It refuses to start otherwise; see +[Where to run the daemon](docs/usage.md#where-to-run-the-daemon). + Point your MCP client at the server — add to the project's `.mcp.json` or `~/.claude/claude_desktop_config.json`: diff --git a/changelog.md b/changelog.md index 06556c6..f807b8e 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,42 @@ Most recent at top. See [docs/formalisation-roadmap.md](docs/formalisation-roadmap.md) for the assurance-ladder context behind the security-formalisation entries. +## Unreleased (1.2.2) — refuse approval terminals other processes can type into (GHSA-cpmp-67wf-gwmx) + +The daemon approves a request by reading one key from its terminal, and it +cannot tell a key the human typed from one injected by another process running +as the same user. The usual requester, an AI agent, also has a same-UID shell. +In tmux or screen (`send-keys`, `stuff`), in a terminal with remote control +(kitty, WezTerm, Konsole's D-Bus `sendText`), or in any X11 session +(`xdotool key y`), it could send a privileged request and answer `y` to its own +prompt, or `a` to grant itself the session. + +- The daemon now checks its terminal at startup (`src/ttyguard.rs`). If it + finds one of these, it prints each reason and refuses to start. Covered: + multiplexer `TERM` or `$TMUX`/`$STY`/`$ZELLIJ`; kitty, WezTerm, Konsole, + VS Code and Emacs terminals; X11 without Wayland. `--allow-injectable-tty` + starts it anyway, with a warning line in every prompt. There is deliberately + no `hosts.json` equivalent: an agent can write that file and restart the + daemon through MCP. `--pkexec` skips the check, since privileged approval + then happens in polkit's dialog. +- With `--host`, the local terminal is checked before ssh starts, and the + override is forwarded to the remote daemon. A remote older than 1.2.2 + rejects the flag and exits, which fails closed. +- Unprivileged children now run in their own session, with no controlling + terminal, so a command (or a background job it leaves) cannot `TIOCSTI` + keystrokes into a later prompt. A kernel that still allows `TIOCSTI` is + reported as a warning. +- `sudo-proxy-mcp` removes the launcher's own terminal variables (`TMUX`, + `KITTY_*`, …) from the window it spawns, so a fresh window is not refused for + the agent's tmux. If the daemon refuses, the window stays open until Enter, + and the `start_server` error explains what to do. +- Docs: threat-model B3 row and attack-tree leaf 3.5 with residuals, + assurance-case assumption A1, security/usage/install/README. + +Residuals: an XWayland terminal inside a Wayland session, emulators the check +does not know, and X11 synthetic input into the polkit dialog under `--pkexec`. +The structural fix is to run the agent as a separate Unix user. + ## Unreleased (1.2.2) — the `Resolves:` line names the binary that actually runs (#62, backport of #80) The prompt resolved `argv[0]` on the daemon's own PATH, but the executor diff --git a/docs/assurance-case.md b/docs/assurance-case.md index 95a9629..7ac0bd5 100644 --- a/docs/assurance-case.md +++ b/docs/assurance-case.md @@ -66,7 +66,7 @@ asserted, evidence not yet produced). |------|------|-----------| | **C1** | Context | The Target of Evaluation is the `sudo-proxy` daemon, the `sudo-proxy-mcp` server, and the `--host` SSH-tunnel path. Out of scope: the AI model, the operator's judgement when reading the prompt. | | **C2** | Context | Adversaries: **A1** prompt-injected MCP caller; **A2** same-UID local process (direct socket); **A3** network MITM / malicious remote. (See [security-audit.md](security-audit.md#threat-model).) | -| **A1** | Assumption | `/dev/tty` is trusted: what the daemon writes is what the human sees, and the keypress read is the human's. | +| **A1** | Assumption | `/dev/tty` is trusted: what the daemon writes is what the human sees, and the keypress read is the human's. The second half is false on a terminal other same-UID processes can type into (GHSA-cpmp-67wf-gwmx). So the daemon refuses the terminals it can recognise as such unless started with `--allow-injectable-tty`, and its unprivileged children have no controlling terminal. Residuals: [threat-model.md](threat-model.md#coverage-and-residuals) 3.5. | | **A2** | Assumption | `sudo` (and `pkexec`) correctly enforce escalation and `env_reset`; the kernel enforces socket permissions and `SO_PEERCRED`. | | **A3** | Assumption | The host is effectively single-user *or* the operator accepts that any same-UID process is already inside the trust boundary for non-privileged actions (finding F2). | | **A4** | Assumption | For the SSH path, remote hosts are in `known_hosts` before first use (or `StrictHostKeyChecking=accept-new` is configured) — this gives payload confidentiality and lets the daemon reach the genuine remote; **and** the daemon authenticates to the remote by key (the remote's `authorized_keys`), which gives command authenticity at the remote. The ProVerif model ([`proofs/proverif/`](../proofs/proverif/)) makes both halves explicit and shows which guarantee rests on which. | diff --git a/docs/install.md b/docs/install.md index 3cd6074..cc0c0cb 100644 --- a/docs/install.md +++ b/docs/install.md @@ -63,6 +63,10 @@ sudo pkexec-cache --create Then configure your MCP client — see [MCP server](mcp.md). +The daemon refuses to start in a terminal other processes can type into (tmux, +screen, X11, kitty/WezTerm remote control, …). Run it in a terminal window of +its own on Wayland; see [Where to run the daemon](usage.md#where-to-run-the-daemon). + ## Building locally ```bash diff --git a/docs/security.md b/docs/security.md index 5bb79c1..a3f4bd6 100644 --- a/docs/security.md +++ b/docs/security.md @@ -37,8 +37,31 @@ the user during TUI approval. **Execution isolation:** child processes run with cwd `/`, umask 0077, and stdout/stderr piped — they do not inherit the socket file descriptor. stdin is -null except for sudo mode, which inherits the terminal so sudo can prompt for a -password. +null. Privileged children (sudo, pkexec) stay in the daemon's session so sudo +can open the terminal for its password prompt. Unprivileged children run in a +session of their own, with **no controlling terminal**, so they cannot inject +keystrokes into the approval prompt with `TIOCSTI` (GHSA-cpmp-67wf-gwmx). + +**Approval terminal (GHSA-cpmp-67wf-gwmx):** the prompt cannot tell a key the +human typed from one another process running as the same user injected, and +an AI requester typically has a same-UID shell. So the daemon refuses to start +in a terminal that accepts synthetic input from other processes: + +- tmux, GNU screen, zellij (`TERM`, `$TMUX`, `$STY`, `$ZELLIJ`); +- kitty, WezTerm, Konsole (remote control), VS Code's integrated terminal, + Emacs terminals; +- any terminal in an X11 session (XTEST, e.g. `xdotool key y`). + +It prints each reason and exits. Run it in a terminal window of its own, on +Wayland (GNOME Terminal, foot, Alacritty, …). `sudo-proxy --allow-injectable-tty` +starts it anyway, and every prompt then carries a warning line. The override +has no `hosts.json` equivalent because an agent can write that file: +whoever starts the daemon decides. A kernel that still allows `TIOCSTI` +(`dev.tty.legacy_tiocsti`, or no such sysctl before 6.2) is reported as a +warning. Detection is best effort; see the residuals in +[threat-model.md](threat-model.md#coverage-and-residuals). The strongest +setup is to run the agent as a **separate Unix user**, or in a sandbox without +access to your display or your multiplexer's socket. **TUI hardening:** the Y/N prompt reads a single keypress in non-canonical terminal mode (no Enter required) and times out after 60 seconds (default deny). diff --git a/docs/threat-model.md b/docs/threat-model.md index 78d7ce2..f861b83 100644 --- a/docs/threat-model.md +++ b/docs/threat-model.md @@ -73,6 +73,7 @@ invariant at a given boundary are omitted. | Tampering | A huge argument pushes the real command and `[y/N]` off-screen. | Displayed command length bounded with a hidden-bytes marker. | G4.3 / F3 | | DoS | Operator never answers, leaving the gate open. | 60 s timeout, default **deny**. | G5.2 | | Elevation | Social-engineer the human into approving. | Covered by G4; residual printable-range look-alikes accepted. | G4.4 (residual) | +| Spoofing | A same-UID process **types the answer itself**: synthetic keystrokes into the approval terminal (`tmux send-keys`, `screen -X stuff`, kitty/wezterm remote control, Konsole D-Bus, X11 XTEST, `TIOCSTI`). The typical requester (an agent) has a same-UID shell, so A1 reaches this as A2. | The daemon refuses to start in a terminal that accepts such input (`ttyguard`: multiplexer `TERM`/`$TMUX`/`$STY`/`$ZELLIJ`, remote-control emulators, VS Code, Emacs, X11 without Wayland) unless started with `--allow-injectable-tty`, which puts a warning line in every prompt. There is deliberately no `hosts.json` equivalent, since an agent can write that file and restart the daemon through MCP. Unprivileged children run in their own session, with no controlling terminal, so they cannot `TIOCSTI` into the prompt. Legacy `TIOCSTI` is reported at startup. `sudo-proxy-mcp` scrubs the launcher's terminal variables from the window it spawns. | A1 (assumption, now checked) / GHSA-cpmp-67wf-gwmx | ### B4 — daemon → exec → root (A1) @@ -135,8 +136,12 @@ A A root command runs that the human did NOT approve │ │ [resolved path + "-> target" shown → G4.2 · blocked] │ ├─ 3.3 Push the real command / [y/N] off-screen with a huge arg │ │ [length bound + hidden-bytes marker → G4.3 / F3 · blocked] -│ └─ 3.4 Printable-range Unicode look-alike / NBSP in reason -│ [cannot hide the real command → G4.4 · residual (accepted)] +│ ├─ 3.4 Printable-range Unicode look-alike / NBSP in reason +│ │ [cannot hide the real command → G4.4 · residual (accepted)] +│ └─ 3.5 Answer the prompt without the human: inject `y` into the TTY +│ [startup refusal of injectable terminals; children without a +│ controlling tty → A1 / GHSA-cpmp-67wf-gwmx +│ · blocked for detected terminals (residual: undetected ones)] │ └─ 4 Execute around the gate entirely (defeat G5 / G6) ├─ 4.1 Direct same-UID socket client bypassing MCP validate_host @@ -166,6 +171,18 @@ is unaccounted for. The residuals — already on record and accepted — are: - **loopback self-routing (F5, closed).** `is_local_host` normalizes self/loopback targets; residual undetected aliases are covered by the C10 composition (every remote daemon still gates unattended exec). See finding F5. +- **3.5 — keystroke injection into the approval terminal + (GHSA-cpmp-67wf-gwmx).** Detection reads environment variables and one sysctl, + so it is best effort. It does not see an XWayland terminal (e.g. `xterm`) + inside a Wayland session, an emulator with remote control it does not know, + or a process that shares the daemon's controlling terminal on a kernel that + still allows `TIOCSTI`. Nor does it cover `--pkexec`, whose polkit dialog has + X11's own synthetic-input exposure, or a daemon the operator started with + `--allow-injectable-tty`. An agent can always start a daemon of its own in a + terminal it controls; that daemon's `sudo` then has no cached credential for + the new terminal and asks for the password. The structural fix is to run the + agent as a separate Unix user, or in a sandbox without access to the display + or the multiplexer's socket. - **3.4 — look-alike `reason` (F1 residual).** Printable Unicode can mislead but cannot conceal the real command line, which is printed separately. - **4.2 — SSH first-contact MITM (assumption A4).** The ssh invocation sets no diff --git a/docs/usage.md b/docs/usage.md index 2353ebd..9dc6bca 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -54,6 +54,10 @@ sudo-proxy --unattended-eligible # Custom socket path sudo-proxy --socket /tmp/my-proxy.sock +# Start even in a terminal other processes can type into (tmux, X11, …). +# Every prompt then shows a warning; see "Where to run the daemon" below. +sudo-proxy --allow-injectable-tty + # Send a request (debug client) sudo-request id sudo-request --reason "install web server" apt install nginx @@ -65,6 +69,23 @@ sudo-request --no-privilege ls /etc sudo-request --session my-project apt update ``` +## Where to run the daemon + +The approval prompt trusts the keypress it reads. Since 1.2.2 the daemon +refuses to start in a terminal that other processes running as you can type +into: tmux/screen/zellij panes, kitty/WezTerm/Konsole (remote control), VS +Code's or Emacs' terminal, and any terminal in an X11 session. It prints why +and exits (GHSA-cpmp-67wf-gwmx). Run it in a terminal window of its own on +Wayland. If the MCP server's `start_server` fails for this reason, start +`sudo-proxy` (or `sudo-proxy --host HOST`) yourself in such a terminal; +`start_server` then finds it running. To accept the risk, start it yourself +with `--allow-injectable-tty`. There is no `hosts.json` setting for this. + +With `--host`, the check runs on the local terminal, where the remote prompt +is answered. The remote daemon checks too, and receives +`--allow-injectable-tty` when you passed it locally. A remote older than 1.2.2 +rejects that flag, so upgrade remotes first. + ## Remote hosts over SSH `sudo-proxy --host HOST` resolves the remote UID (cached in diff --git a/src/bin/sudo-proxy.rs b/src/bin/sudo-proxy.rs index 4fe6151..8c3ed69 100644 --- a/src/bin/sudo-proxy.rs +++ b/src/bin/sudo-proxy.rs @@ -17,6 +17,11 @@ struct Opts { /// `Some(_)` = an explicit CLI flag was passed and overrides the file. unattended_eligible: Option, forward_agent: bool, + /// `--allow-injectable-tty` (GHSA-cpmp-67wf-gwmx). Deliberately a CLI + /// flag only, with no `hosts.json` equivalent: an agent can write that + /// file, then restart the daemon through `sudo-proxy-mcp`, which never + /// passes this flag. + allow_injectable_tty: bool, } fn main() { @@ -35,7 +40,10 @@ fn main() { } } let target = sudo_proxy::hosts::ssh_target(host, opts.login.as_deref()); - run_remote(&target, opts.verbose, opts.forward_agent); + // The remote prompt is answered through *this* terminal, so it is + // this terminal that must not accept injected keystrokes. + let overridden = tty_gate(opts.allow_injectable_tty); + run_remote(&target, opts.verbose, opts.forward_agent, overridden); // run_remote execs into ssh, so we only get here on error return; } @@ -95,6 +103,16 @@ fn main() { } }); + // GHSA-cpmp-67wf-gwmx: refuse a terminal other same-UID processes can + // type into, unless overridden. Under --pkexec, privileged requests are + // approved in polkit's dialog, not here, and an injected key at the TTY + // prompt yields only unprivileged execution, which such a process + // already has — so the check is skipped. + if !opts.pkexec { + let reasons = tty_gate(opts.allow_injectable_tty); + sudo_proxy::tui::set_injectable_tty_warning(reasons); + } + let config = server::ServerConfig { mode, pkexec_only: opts.pkexec, @@ -134,6 +152,41 @@ fn main() { } } +/// GHSA-cpmp-67wf-gwmx: check that this terminal does not accept keystrokes +/// injected by other same-UID processes. Prints any warnings. When injectors +/// are found and `allow` is false, prints the refusal and exits 1 (holding +/// the window open first if `sudo-proxy-mcp` spawned it). Returns the +/// injector reasons when overridden (empty when the terminal is clean). +fn tty_gate(allow: bool) -> Vec { + use sudo_proxy::ttyguard; + let a = ttyguard::assess(&ttyguard::probe()); + for w in &a.warnings { + eprintln!("sudo-proxy: warning: {w}"); + } + if a.injectors.is_empty() { + return Vec::new(); + } + if !allow { + eprintln!("{}", ttyguard::refusal_message(&a)); + if std::env::var_os(ttyguard::HOLD_ENV).is_some_and(|v| !v.is_empty()) { + // Spawned in a window of its own: keep it open so the reason + // can be read before it closes. + eprintln!("\nPress Enter to close this window."); + let mut line = String::new(); + let _ = std::io::stdin().read_line(&mut line); + } + process::exit(1); + } + eprintln!( + "sudo-proxy: WARNING: other processes running as you can type into this terminal; \ + starting anyway (--allow-injectable-tty):" + ); + for i in &a.injectors { + eprintln!(" - {i}"); + } + a.injectors +} + fn parse_args(args: &[String]) -> Opts { let mut socket = None; let mut host = None; @@ -144,6 +197,7 @@ fn parse_args(args: &[String]) -> Opts { // Some(_) means an explicit flag overrides the file. let mut unattended_eligible: Option = None; let mut forward_agent = false; + let mut allow_injectable_tty = false; let mut iter = args.iter().skip(1); while let Some(arg) = iter.next() { match arg.as_str() { @@ -164,9 +218,10 @@ fn parse_args(args: &[String]) -> Opts { "--unattended-eligible" => unattended_eligible = Some(true), "--no-unattended-eligible" => unattended_eligible = Some(false), "--forward-agent" => forward_agent = true, + "--allow-injectable-tty" => allow_injectable_tty = true, "--version" | "-V" => sudo_proxy::cli::print_version("sudo-proxy"), "--help" | "-h" => { - eprintln!("Usage: sudo-proxy [--socket PATH] [--host HOST] [--pkexec] [-v] [--unattended-eligible] [--forward-agent]"); + eprintln!("Usage: sudo-proxy [--socket PATH] [--host HOST] [--pkexec] [-v] [--unattended-eligible] [--forward-agent] [--allow-injectable-tty]"); eprintln!(); eprintln!("Privileged command execution proxy."); eprintln!("Listens on a Unix socket for JSON requests and executes them via pkexec or sudo."); @@ -184,6 +239,10 @@ fn parse_args(args: &[String]) -> Opts { eprintln!(" and its directories are yours and not group/world-writable"); eprintln!(" --forward-agent With --host: enable SSH agent forwarding (-A) so unprivileged"); eprintln!(" commands that opt in via forward_agent can use the local agent"); + eprintln!(" --allow-injectable-tty Start even if other processes running as you can type into this"); + eprintln!(" terminal (tmux/screen, kitty/wezterm remote control, X11, …) and"); + eprintln!(" so answer the prompt; every prompt then shows a warning"); + eprintln!(" (no hosts.json equivalent: whoever starts the daemon decides)"); std::process::exit(0); } _ => { @@ -200,6 +259,7 @@ fn parse_args(args: &[String]) -> Opts { verbose, unattended_eligible, forward_agent, + allow_injectable_tty, } } @@ -247,7 +307,7 @@ unsafe fn signal_hook_cleanup(path: PathBuf) { } /// Connect to a remote host: resolve UID, set up SSH tunnel, exec into SSH. -fn run_remote(host: &str, verbose: bool, forward_agent: bool) { +fn run_remote(host: &str, verbose: bool, forward_agent: bool, injectable_overridden: Vec) { use std::os::unix::process::CommandExt; use sudo_proxy::hosts::HostsConfig; @@ -299,6 +359,12 @@ fn run_remote(host: &str, verbose: bool, forward_agent: bool) { } ssh_args.push(host); ssh_args.push("sudo-proxy"); + // The override was accepted for the terminal the remote prompt shows in; + // pass it on so the remote daemon (whose TERM comes from here) agrees. + // A remote older than 1.2.2 rejects the flag and exits: fail closed. + if !injectable_overridden.is_empty() { + ssh_args.push("--allow-injectable-tty"); + } if verbose { eprintln!("+ ssh {}", ssh_args.join(" ")); diff --git a/src/executor.rs b/src/executor.rs index e26decf..97fa774 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -349,19 +349,33 @@ fn run_single_command( timeout: Duration, fg_lock: Option<&Mutex<()>>, ) -> Response { + let needs_tty = fg_lock.is_some(); unsafe { - cmd.pre_exec(|| { + cmd.pre_exec(move || { // New process group so kill_group can SIGKILL the entire // group on timeout — otherwise a wrapper like `sh -c '... &'` // would leave grandchild processes orphaned to PID 1, holding // stdio pipes open and blocking our drain threads forever. // - // setpgid (vs the historical setsid) keeps the child in the - // *same session* as the daemon, so the controlling terminal - // stays reachable. Under setsid the child had no controlling - // tty, and `sudo` could not open /dev/tty for its password - // prompt — see issue #19. - libc::setpgid(0, 0); + // Privileged children (sudo, pkexec) use setpgid, which keeps + // them in the daemon's *session* so the controlling terminal + // stays reachable: under setsid `sudo` could not open /dev/tty + // for its password prompt — see issue #19. + // + // Unprivileged children get their own session (setsid), so they + // have no controlling terminal at all. A child that shared the + // daemon's could inject keystrokes into the approval prompt + // with TIOCSTI (where `dev.tty.legacy_tiocsti` allows it) and + // approve a later privileged request — e.g. a background job + // left by a command run under the session `a` grant + // (GHSA-cpmp-67wf-gwmx). They never read /dev/tty anyway + // (stdin is null, no foreground hand-off); setsid also makes + // the child the leader of a new group, so kill_group still works. + if needs_tty { + libc::setpgid(0, 0); + } else { + libc::setsid(); + } libc::umask(0o077); Ok(()) }); @@ -378,8 +392,12 @@ fn run_single_command( // setpgid with the same args is harmless; if the child has already // exec'd, EACCES is returned and we fall back to whatever the child // managed to set itself. - unsafe { - let _ = libc::setpgid(cpid, cpid); + // (Not for a setsid child: a session leader cannot change group, and + // setsid already made it the leader of group `cpid`.) + if needs_tty { + unsafe { + let _ = libc::setpgid(cpid, cpid); + } } // Hand the controlling terminal's foreground to the child so reads diff --git a/src/lib.rs b/src/lib.rs index c4bf4f9..fd266ba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,3 +23,4 @@ pub(crate) mod prop; pub mod protocol; pub mod server; pub mod tui; +pub mod ttyguard; diff --git a/src/mcp.rs b/src/mcp.rs index fa7f21e..260f22f 100644 --- a/src/mcp.rs +++ b/src/mcp.rs @@ -690,6 +690,7 @@ async fn start_local() -> Result { cmd.stdin(Stdio::null()) .stdout(Stdio::null()) .stderr(Stdio::null()); + scrub_launcher_terminal(&mut cmd); // Pass the proxy binary as a separate argv element so the terminal exec // path never goes through `sh -c`. This closes a command-injection // vector when user-controlled fields ever land in this code path. @@ -726,7 +727,7 @@ async fn start_local() -> Result { } Ok(error_result(format!( - "Terminal opened but socket not ready after 5s at {}", + "Terminal opened but socket not ready after 5s at {}. {REFUSAL_HINT}", socket_path.display() ))) } @@ -762,6 +763,7 @@ async fn start_remote(host: &str, forward_agent: bool) -> Result Result, + /// Contents of `/proc/sys/dev/tty/legacy_tiocsti`, trimmed; `None` when + /// the file is absent (kernel < 6.2, where TIOCSTI is always allowed). + pub legacy_tiocsti: Option, +} + +impl Probe { + fn get(&self, k: &str) -> Option<&str> { + self.env.get(k).map(String::as_str).filter(|v| !v.is_empty()) + } +} + +/// The verdict of [`assess`]. +#[derive(Debug, Clone, Default, PartialEq, Eq)] +pub struct Assessment { + /// Ways a same-UID process can type into this terminal. Non-empty means + /// the daemon refuses to start unless overridden. Each entry is one line + /// naming the mechanism and the signal that revealed it. + pub injectors: Vec, + /// Weaker exposures that are reported but do not refuse. + pub warnings: Vec, +} + +/// Read the environment and the TIOCSTI sysctl. +pub fn probe() -> Probe { + let env = VARS + .iter() + .filter_map(|k| { + std::env::var(k).ok().filter(|v| !v.is_empty()).map(|v| (k.to_string(), v)) + }) + .collect(); + let legacy_tiocsti = std::fs::read_to_string("/proc/sys/dev/tty/legacy_tiocsti") + .ok() + .map(|s| s.trim().to_string()); + Probe { env, legacy_tiocsti } +} + +/// Classify a [`Probe`]. Pure. +pub fn assess(p: &Probe) -> Assessment { + let mut a = Assessment::default(); + let inj = &mut a.injectors; + + // Multiplexers: any same-UID process can type into any pane + // (`tmux send-keys`, `screen -X stuff`, `zellij action write-chars`) and + // read it back to time the key. TERM survives ssh and nesting; the + // socket variables catch a pane whose TERM was overridden. + if let Some(t) = p.get("TERM").filter(|t| t.starts_with("tmux") || t.starts_with("screen")) { + inj.push(format!("terminal multiplexer (TERM={t}): `tmux send-keys` / `screen -X stuff` can type into it")); + } else if p.get("TMUX").is_some() { + inj.push("tmux pane ($TMUX set): `tmux send-keys` can type into it".into()); + } else if p.get("STY").is_some() { + inj.push("GNU screen window ($STY set): `screen -X stuff` can type into it".into()); + } + if p.get("ZELLIJ").is_some() { + inj.push("zellij pane ($ZELLIJ set): `zellij action write-chars` can type into it".into()); + } + + // Emulators with a remote-control channel open to same-UID processes. + if p.get("KITTY_LISTEN_ON").is_some() { + inj.push("kitty with remote control listening ($KITTY_LISTEN_ON): `kitty @ send-text` can type into it".into()); + } else if p.get("KITTY_WINDOW_ID").is_some() { + inj.push("kitty ($KITTY_WINDOW_ID set): `kitty @ send-text` can type into it when allow_remote_control is on".into()); + } + if p.get("WEZTERM_PANE").is_some() || p.get("WEZTERM_UNIX_SOCKET").is_some() { + inj.push("WezTerm ($WEZTERM_PANE set): `wezterm cli send-text` can type into it".into()); + } + if p.get("KONSOLE_DBUS_SERVICE").is_some() { + inj.push("Konsole ($KONSOLE_DBUS_SERVICE set): its D-Bus `sendText` can type into it".into()); + } + if p.get("TERM_PROGRAM") == Some("vscode") { + inj.push("VS Code integrated terminal (TERM_PROGRAM=vscode): extensions can `sendText` into it".into()); + } + if p.get("INSIDE_EMACS").is_some() { + inj.push("Emacs terminal ($INSIDE_EMACS set): `emacsclient --eval` can send input to it".into()); + } + + // X11: any client may synthesise keys (XTEST, e.g. `xdotool key y`). + let x11 = p.get("DISPLAY").is_some() + && (p.get("WAYLAND_DISPLAY").is_none() || p.get("XDG_SESSION_TYPE") == Some("x11")); + if x11 { + inj.push(format!( + "X11 session (DISPLAY={}, no Wayland): any X client can synthesise keys (`xdotool key y`)", + p.get("DISPLAY").unwrap_or("") + )); + } + + // TIOCSTI only works on the caller's own controlling terminal. The + // daemon's unprivileged children run in their own session (no + // controlling terminal), so what remains is another process that shares + // this terminal: reported, not refused. + match p.legacy_tiocsti.as_deref() { + Some("0") => {} + other => a.warnings.push(format!( + "the kernel allows TIOCSTI ({}): a process sharing this terminal could inject keystrokes; \ + set `sysctl dev.tty.legacy_tiocsti=0` where available", + match other { + None => "no dev.tty.legacy_tiocsti, kernel < 6.2".to_string(), + Some(v) => format!("dev.tty.legacy_tiocsti={v}"), + } + )), + } + a +} + +/// The refusal printed to stderr when [`Assessment::injectors`] is non-empty +/// and not overridden. +pub fn refusal_message(a: &Assessment) -> String { + let mut s = String::from( + "sudo-proxy: refusing to start: other processes running as you can type into this terminal,\n\ + so they could answer the approval prompt themselves (GHSA-cpmp-67wf-gwmx):\n", + ); + for i in &a.injectors { + s.push_str(&format!(" - {i}\n")); + } + s.push_str( + "Run the daemon in a terminal window of its own, outside any multiplexer, on Wayland\n\ + (e.g. GNOME Terminal, foot, Alacritty). Running the agent as a separate Unix user\n\ + removes the risk altogether.\n\ + To accept the risk anyway, start it yourself with --allow-injectable-tty.", + ); + s +} + +#[cfg(test)] +mod tests { + use super::*; + + fn probe_of(vars: &[(&str, &str)], tiocsti: Option<&str>) -> Probe { + Probe { + env: vars.iter().map(|(k, v)| (k.to_string(), v.to_string())).collect(), + legacy_tiocsti: tiocsti.map(str::to_string), + } + } + + fn injectors(vars: &[(&str, &str)]) -> Vec { + assess(&probe_of(vars, Some("0"))).injectors + } + + #[test] + fn clean_wayland_terminal_is_accepted() { + let a = assess(&probe_of( + &[ + ("TERM", "xterm-256color"), + ("WAYLAND_DISPLAY", "wayland-0"), + ("DISPLAY", ":0"), + ("XDG_SESSION_TYPE", "wayland"), + ], + Some("0"), + )); + assert_eq!(a, Assessment::default()); + } + + #[test] + fn headless_ssh_session_is_accepted() { + assert!(injectors(&[("TERM", "xterm-256color")]).is_empty()); + } + + #[test] + fn multiplexers_are_detected() { + for term in ["tmux-256color", "screen", "screen-256color"] { + let i = injectors(&[("TERM", term)]); + assert_eq!(i.len(), 1, "{term}: {i:?}"); + assert!(i[0].contains(term)); + } + // TERM overridden inside the multiplexer: the socket variable still counts. + assert_eq!(injectors(&[("TERM", "xterm-256color"), ("TMUX", "/tmp/tmux-1/default,1,0")]).len(), 1); + assert_eq!(injectors(&[("TERM", "xterm-256color"), ("STY", "123.pts-0")]).len(), 1); + assert_eq!(injectors(&[("TERM", "xterm-256color"), ("ZELLIJ", "0")]).len(), 1); + // One line for tmux, not one per signal. + assert_eq!(injectors(&[("TERM", "tmux-256color"), ("TMUX", "x")]).len(), 1); + } + + #[test] + fn remote_control_emulators_are_detected() { + for (k, v, needle) in [ + ("KITTY_LISTEN_ON", "unix:/tmp/kitty", "kitty"), + ("KITTY_WINDOW_ID", "1", "kitty"), + ("WEZTERM_PANE", "0", "WezTerm"), + ("WEZTERM_UNIX_SOCKET", "/run/user/1/wezterm/sock", "WezTerm"), + ("KONSOLE_DBUS_SERVICE", ":1.42", "Konsole"), + ("TERM_PROGRAM", "vscode", "VS Code"), + ("INSIDE_EMACS", "29.1,vterm", "Emacs"), + ] { + let i = injectors(&[("TERM", "xterm-256color"), (k, v)]); + assert_eq!(i.len(), 1, "{k}: {i:?}"); + assert!(i[0].contains(needle), "{k}: {i:?}"); + } + // Another TERM_PROGRAM is not a remote-control signal. + assert!(injectors(&[("TERM_PROGRAM", "Apple_Terminal")]).is_empty()); + } + + #[test] + fn x11_without_wayland_is_detected() { + let i = injectors(&[("DISPLAY", ":0")]); + assert_eq!(i.len(), 1); + assert!(i[0].contains("X11")); + // Wayland session: DISPLAY alone is XWayland for X clients, not this terminal. + assert!(injectors(&[("DISPLAY", ":0"), ("WAYLAND_DISPLAY", "wayland-0")]).is_empty()); + // A Wayland socket in an X11 session (nested compositor) does not clear it. + assert_eq!( + injectors(&[("DISPLAY", ":0"), ("WAYLAND_DISPLAY", "w"), ("XDG_SESSION_TYPE", "x11")]).len(), + 1 + ); + // ssh -X forwarding exposes the local X server too. + assert_eq!(injectors(&[("DISPLAY", "localhost:10.0")]).len(), 1); + } + + #[test] + fn several_mechanisms_are_all_listed() { + let i = injectors(&[("TERM", "tmux-256color"), ("DISPLAY", ":0"), ("KITTY_WINDOW_ID", "1")]); + assert_eq!(i.len(), 3, "{i:?}"); + } + + #[test] + fn empty_values_are_ignored() { + assert!(injectors(&[("TMUX", ""), ("DISPLAY", ""), ("KITTY_WINDOW_ID", "")]).is_empty()); + } + + #[test] + fn legacy_tiocsti_warns_but_does_not_refuse() { + for v in [None, Some("1")] { + let a = assess(&probe_of(&[], v)); + assert!(a.injectors.is_empty(), "{v:?}"); + assert_eq!(a.warnings.len(), 1, "{v:?}"); + assert!(a.warnings[0].contains("TIOCSTI")); + } + assert!(assess(&probe_of(&[], Some("0"))).warnings.is_empty()); + } + + #[test] + fn refusal_names_every_reason_and_the_override() { + let a = assess(&probe_of(&[("TERM", "tmux-256color"), ("DISPLAY", ":0")], Some("0"))); + let m = refusal_message(&a); + for i in &a.injectors { + assert!(m.contains(i.as_str())); + } + assert!(m.contains("--allow-injectable-tty")); + assert!(!m.contains("hosts.json"), "no file-based override: {m}"); + assert!(m.contains("GHSA-cpmp-67wf-gwmx")); + } + + #[test] + fn inherited_vars_cover_every_rule_var_except_display_and_term() { + // Everything the rules read about the *launcher's* terminal must be + // scrubbed by the MCP launcher; DISPLAY/WAYLAND/TERM describe the new + // window and must stay. + for v in VARS { + let keep = ["TERM", "DISPLAY", "WAYLAND_DISPLAY", "XDG_SESSION_TYPE"]; + assert_eq!( + INHERITED_TERMINAL_VARS.contains(v), + !keep.contains(v), + "{v}" + ); + } + } +} diff --git a/src/tui.rs b/src/tui.rs index e8af694..2c2e528 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -152,6 +152,33 @@ pub(crate) fn classify_key(key: Option, privileged: bool) -> PromptResult { } } +/// Why this daemon's terminal accepts injected keystrokes, when the operator +/// started it anyway (`--allow-injectable-tty`, GHSA-cpmp-67wf-gwmx). Set once +/// at startup; every prompt then carries a warning line. +static INJECTABLE_TTY: std::sync::OnceLock> = std::sync::OnceLock::new(); + +/// Record the injectable-terminal reasons shown in every prompt header. +pub fn set_injectable_tty_warning(reasons: Vec) { + let _ = INJECTABLE_TTY.set(reasons); +} + +/// The prompt's warning line for an injectable terminal, or `None`. +fn injectable_tty_line(reasons: &[String], style: &Style) -> Option { + if reasons.is_empty() { + return None; + } + let Style { bold, reset, .. } = *style; + Some(format!( + "{bold}⚠ Other processes can type into this terminal ({}). \ + Approve only what you asked for.{reset}", + reasons + .iter() + .map(|r| r.split(": ").next().unwrap_or(r).trim()) + .collect::>() + .join("; ") + )) +} + /// Display a privilege request on /dev/tty and ask for Y/N confirmation. /// `eligible` gates whether the session-scoped `a` answer is offered (only for /// unprivileged requests on a daemon whose `unattended_eligible` policy is set). @@ -167,6 +194,9 @@ pub fn prompt_tty( let Style { bold, dim, reset } = st; writeln!(tty_w, "\n{bold}━━━ Privilege Request ━━━{reset}")?; + if let Some(line) = INJECTABLE_TTY.get().and_then(|r| injectable_tty_line(r, &st)) { + writeln!(tty_w, "{line}")?; + } writeln!( tty_w, "From: {} @ {}", @@ -554,6 +584,23 @@ mod tests { String::from_utf8(buf).expect("utf8") } + #[test] + fn injectable_tty_line_names_each_mechanism() { + let st = Style { bold: "B", dim: "D", reset: "R" }; + assert_eq!(injectable_tty_line(&[], &st), None); + let line = injectable_tty_line( + &[ + "terminal multiplexer (TERM=tmux-256color): `tmux send-keys` can type into it".into(), + "X11 session (DISPLAY=:0, no Wayland): any X client can synthesise keys".into(), + ], + &st, + ) + .unwrap(); + assert!(line.starts_with("B⚠"), "{line}"); + assert!(line.ends_with('R'), "{line}"); + assert!(line.contains("terminal multiplexer (TERM=tmux-256color); X11 session (DISPLAY=:0, no Wayland)"), "{line}"); + } + #[test] fn style_for_honors_no_color() { let on = style_for(false); diff --git a/tests/cli.rs b/tests/cli.rs index 71a9d61..7b12984 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -72,3 +72,104 @@ fn sudo_request_times_out_against_silent_daemon() { drop(server_handle); // detach the fake daemon thread; tempdir cleans up the socket } + +// === GHSA-cpmp-67wf-gwmx: the daemon refuses a terminal other same-UID +// processes can type into, unless started with --allow-injectable-tty. + +/// A `sudo-proxy` command with a controlled environment: only the variables +/// given, plus a throwaway HOME/config dir so no real hosts.json is read. +fn daemon(home: &std::path::Path, vars: &[(&str, &str)], args: &[&str]) -> Command { + let mut c = Command::new(env!("CARGO_BIN_EXE_sudo-proxy")); + c.env_clear() + .env("HOME", home) + .env("XDG_CONFIG_HOME", home.join("cfg")) + .args(args) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()); + for (k, v) in vars { + c.env(k, v); + } + c +} + +#[test] +fn daemon_refuses_injectable_terminal() { + let dir = tempfile::tempdir_in("/tmp").expect("tempdir"); + let sock = dir.path().join("d.sock"); + for vars in [ + vec![("TERM", "tmux-256color")], + vec![("TERM", "xterm-256color"), ("TMUX", "/tmp/tmux-1000/default,1,0")], + vec![("TERM", "xterm-256color"), ("DISPLAY", ":0")], + vec![("TERM", "xterm-kitty"), ("KITTY_WINDOW_ID", "1")], + ] { + let out = daemon(dir.path(), &vars, &["--socket", sock.to_str().unwrap()]) + .output() + .expect("spawn sudo-proxy"); + let err = String::from_utf8_lossy(&out.stderr); + assert_eq!(out.status.code(), Some(1), "{vars:?}: {err}"); + assert!(err.contains("refusing to start"), "{vars:?}: {err}"); + assert!(err.contains("--allow-injectable-tty"), "{vars:?}: {err}"); + assert!(!sock.exists(), "{vars:?}: must refuse before binding the socket"); + } +} + +#[test] +fn daemon_refuses_injectable_terminal_before_ssh_in_host_mode() { + let dir = tempfile::tempdir_in("/tmp").expect("tempdir"); + let out = daemon(dir.path(), &[("TERM", "screen")], &["--host", "example.invalid"]) + .output() + .expect("spawn sudo-proxy"); + let err = String::from_utf8_lossy(&out.stderr); + assert_eq!(out.status.code(), Some(1), "{err}"); + assert!(err.contains("refusing to start"), "{err}"); + // Refused before resolving the remote UID, so no hosts.json was written. + assert!(!dir.path().join("cfg/sudo-proxy/hosts.json").exists()); +} + +#[test] +fn daemon_starts_on_injectable_terminal_with_override() { + let dir = tempfile::tempdir_in("/tmp").expect("tempdir"); + let sock = dir.path().join("d.sock"); + let mut child = daemon( + dir.path(), + &[("TERM", "tmux-256color")], + &["--socket", sock.to_str().unwrap(), "--allow-injectable-tty"], + ) + .spawn() + .expect("spawn sudo-proxy"); + let deadline = Instant::now() + Duration::from_secs(10); + while !sock.exists() && Instant::now() < deadline { + thread::sleep(Duration::from_millis(20)); + } + let bound = sock.exists(); + let _ = child.kill(); + let out = child.wait_with_output().expect("wait"); + let err = String::from_utf8_lossy(&out.stderr); + assert!(bound, "daemon did not bind with --allow-injectable-tty: {err}"); + assert!(err.contains("WARNING"), "override must be announced: {err}"); + assert!(err.contains("TERM=tmux-256color"), "{err}"); +} + +#[test] +fn daemon_starts_on_clean_terminal() { + let dir = tempfile::tempdir_in("/tmp").expect("tempdir"); + let sock = dir.path().join("d.sock"); + let mut child = daemon( + dir.path(), + &[("TERM", "xterm-256color"), ("WAYLAND_DISPLAY", "wayland-0"), ("DISPLAY", ":0")], + &["--socket", sock.to_str().unwrap()], + ) + .spawn() + .expect("spawn sudo-proxy"); + let deadline = Instant::now() + Duration::from_secs(10); + while !sock.exists() && Instant::now() < deadline { + thread::sleep(Duration::from_millis(20)); + } + let bound = sock.exists(); + let _ = child.kill(); + let out = child.wait_with_output().expect("wait"); + let err = String::from_utf8_lossy(&out.stderr); + assert!(bound, "daemon refused a clean Wayland terminal: {err}"); + assert!(!err.contains("refusing"), "{err}"); +} diff --git a/tests/exec.rs b/tests/exec.rs index a4cf16d..606d292 100644 --- a/tests/exec.rs +++ b/tests/exec.rs @@ -268,3 +268,20 @@ fn login_env() -> HashMap { apply_login_env_defaults(&mut env); env } + +/// GHSA-cpmp-67wf-gwmx: an unprivileged child leads its own session, so it has +/// no controlling terminal and cannot TIOCSTI keystrokes into the daemon's +/// approval prompt. `/proc/self/stat` fields 6 and 7 are the session id and +/// tty_nr; checked whether or not the test runner itself has a terminal. +#[test] +fn unprivileged_child_has_no_controlling_terminal() { + let resp = exec_direct(&make_req(vec![vec!["cat", "/proc/self/stat"]]), &login_env()); + assert_eq!(resp.status, Status::Ok, "got {:?}", resp); + let out = String::from_utf8_lossy(&common::b64_decode(resp.stdout.as_deref().unwrap_or(""))).to_string(); + // comm (field 2) is parenthesized and may contain spaces; split after it. + let pid: &str = out.split_whitespace().next().unwrap(); + let rest: Vec<&str> = out[out.rfind(')').unwrap() + 2..].split_whitespace().collect(); + // rest[0]=state, [1]=ppid, [2]=pgrp, [3]=session, [4]=tty_nr + assert_eq!(rest[3], pid, "child must lead its own session: {out}"); + assert_eq!(rest[4], "0", "child must have no controlling tty: {out}"); +} From 199092588d3ba4ee601c9b74327fe552a140fbdf Mon Sep 17 00:00:00 2001 From: Cuihtlauac ALVARADO Date: Sat, 21 Nov 2026 18:04:30 +0100 Subject: [PATCH 3/5] chore: bump version to 1.2.2 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Cuihtlauac ALVARADO --- .claude-plugin/plugin.json | 2 +- Cargo.lock | 2 +- Cargo.toml | 2 +- changelog.md | 22 ++++++++++++++++++++-- packaging/mcpb/manifest.json | 2 +- server.json | 8 ++++---- 6 files changed, 28 insertions(+), 10 deletions(-) diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index 03bb2f5..57b254f 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "sudo-proxy", - "version": "1.2.1", + "version": "1.2.2", "description": "Run privileged commands locally or over SSH, with a human keypress approving each one", "author": { "name": "Tarides" diff --git a/Cargo.lock b/Cargo.lock index 09d269d..354ed14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -573,7 +573,7 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "sudo-proxy" -version = "1.2.1" +version = "1.2.2" dependencies = [ "base64", "libc", diff --git a/Cargo.toml b/Cargo.toml index 0889ca4..a365261 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sudo-proxy" -version = "1.2.1" +version = "1.2.2" edition = "2021" license = "MIT" description = "Privileged command execution proxy with human approval via pkexec or sudo" diff --git a/changelog.md b/changelog.md index f807b8e..03cdfea 100644 --- a/changelog.md +++ b/changelog.md @@ -3,7 +3,25 @@ Most recent at top. See [docs/formalisation-roadmap.md](docs/formalisation-roadmap.md) for the assurance-ladder context behind the security-formalisation entries. -## Unreleased (1.2.2) — refuse approval terminals other processes can type into (GHSA-cpmp-67wf-gwmx) +## v1.2.2 — 2026-11-21 (security release) + +A patch release on top of v1.2.1 with one security fix and one backported +fix, and nothing else (main's 1.3 work is not included): + +- **GHSA-cpmp-67wf-gwmx** (high): the daemon refuses to start in a terminal + that other same-UID processes can type into (tmux/screen, kitty/WezTerm/ + Konsole remote control, X11, …), unless started with + `--allow-injectable-tty`. Unprivileged children no longer share its + controlling terminal. +- **#62** (backport of #80): the `Resolves:` line names the binary that + actually runs. + +**Upgrade note:** if you start the daemon inside tmux/screen or on X11, it now +refuses with an explanation; move it to a terminal of its own on Wayland, or +pass `--allow-injectable-tty`. With `--host`, upgrade the remote first if you +use the override, since a 1.2.1 remote rejects the forwarded flag. + +### Refuse approval terminals other processes can type into (GHSA-cpmp-67wf-gwmx) The daemon approves a request by reading one key from its terminal, and it cannot tell a key the human typed from one injected by another process running @@ -39,7 +57,7 @@ Residuals: an XWayland terminal inside a Wayland session, emulators the check does not know, and X11 synthetic input into the polkit dialog under `--pkexec`. The structural fix is to run the agent as a separate Unix user. -## Unreleased (1.2.2) — the `Resolves:` line names the binary that actually runs (#62, backport of #80) +### The `Resolves:` line names the binary that actually runs (#62, backport of #80) The prompt resolved `argv[0]` on the daemon's own PATH, but the executor spawned the bare name with a cleared environment, so the child searched the diff --git a/packaging/mcpb/manifest.json b/packaging/mcpb/manifest.json index b0a9ce5..3e40dfa 100644 --- a/packaging/mcpb/manifest.json +++ b/packaging/mcpb/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": "0.3", "name": "sudo-proxy", - "version": "1.2.1", + "version": "1.2.2", "description": "Privileged command execution proxy with human approval via pkexec or sudo", "author": { "name": "Tarides" diff --git a/server.json b/server.json index d712c8f..5ef6dfd 100644 --- a/server.json +++ b/server.json @@ -3,7 +3,7 @@ "name": "io.github.tarides/sudo-proxy", "title": "sudo-proxy", "description": "Privileged command execution proxy with human approval via pkexec or sudo", - "version": "1.2.1", + "version": "1.2.2", "repository": { "url": "https://github.com/tarides/sudo-proxy", "source": "github" @@ -13,15 +13,15 @@ "registryType": "cargo", "registryBaseUrl": "https://crates.io", "identifier": "sudo-proxy", - "version": "1.2.1", + "version": "1.2.2", "transport": { "type": "stdio" } }, { "registryType": "mcpb", - "identifier": "https://github.com/tarides/sudo-proxy/releases/download/v1.2.1/sudo-proxy-mcp-v1.2.1-x86_64-linux.mcpb", - "version": "1.2.1", + "identifier": "https://github.com/tarides/sudo-proxy/releases/download/v1.2.2/sudo-proxy-mcp-v1.2.2-x86_64-linux.mcpb", + "version": "1.2.2", "fileSha256": "SHA256-INJECTED-BY-PUBLISH-WORKFLOW", "transport": { "type": "stdio" From 33457282387b3e4a6ba9a3e65fb71e0eac1a7692 Mon Sep 17 00:00:00 2001 From: Cuihtlauac ALVARADO Date: Tue, 10 Nov 2026 08:28:39 +0100 Subject: [PATCH 4/5] fix(deps): clear new RustSec advisories failing cargo deny / cargo audit - tokio 1.49 -> 1.54.1 (RUSTSEC-2026-0386, unsound AsyncFd constructors); the requirement floor is raised to 1.54 so the lockfile can't regress. - futures-util 0.3.31 -> 0.3.34, which drops the unmaintained pin-utils (RUSTSEC-2026-0441). - Ignore RUSTSEC-2026-0462 in deny.toml and the cargo audit step: it is unbounded body buffering in rmcp's Streamable HTTP *clients*, and sudo-proxy enables only rmcp's stdio `transport-io`. The real fix is rmcp >= 3.9.0, a major-version upgrade left for a separate change. Co-Authored-By: Claude Opus 5.5 (cherry picked from commit 20ab260ada6bd003c33b92313d58a5d58f407a21) Signed-off-by: Cuihtlauac ALVARADO --- .github/workflows/ci.yml | 2 +- Cargo.lock | 190 +++++++++++++-------------------------- Cargo.toml | 2 +- deny.toml | 7 ++ 4 files changed, 69 insertions(+), 132 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 27d8927..95c5769 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,7 +53,7 @@ jobs: # RUSTSEC-2026-0189 ignored: DNS rebinding in rmcp's Streamable HTTP # server transport, which sudo-proxy does not use (stdio only; see the # documented rationale in deny.toml [advisories].ignore). - - run: cargo audit --ignore RUSTSEC-2026-0189 + - run: cargo audit --ignore RUSTSEC-2026-0189 --ignore RUSTSEC-2026-0462 deny: name: cargo deny diff --git a/Cargo.lock b/Cargo.lock index 354ed14..7b96891 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,7 +19,7 @@ checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.115", ] [[package]] @@ -108,7 +108,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn", + "syn 2.0.115", ] [[package]] @@ -119,7 +119,7 @@ checksum = "ac3984ec7bd6cfa798e62b4a642426a5be0e68f9401cfc2a01e3fa9ea2fcdb8d" dependencies = [ "darling_core", "quote", - "syn", + "syn 2.0.115", ] [[package]] @@ -135,7 +135,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys", ] [[package]] @@ -152,9 +152,9 @@ checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" [[package]] name = "futures" -version = "0.3.31" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" +checksum = "9a31d2a3fbaaeb2af2368bbdd904aa8e812d3c04a1ee10d3171f52d556e5d0a3" dependencies = [ "futures-channel", "futures-core", @@ -167,9 +167,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.31" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" dependencies = [ "futures-core", "futures-sink", @@ -177,15 +177,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.31" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" [[package]] name = "futures-executor" -version = "0.3.31" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +checksum = "031b47cf1a3c6cc8bc2fc76cd437f521619387907d469316e7c0bc278f1f5432" dependencies = [ "futures-core", "futures-task", @@ -194,38 +194,38 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.31" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" +checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" [[package]] name = "futures-macro" -version = "0.3.31" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 3.0.10", ] [[package]] name = "futures-sink" -version = "0.3.31" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" +checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d" [[package]] name = "futures-task" -version = "0.3.31" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" [[package]] name = "futures-util" -version = "0.3.31" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" dependencies = [ "futures-channel", "futures-core", @@ -235,7 +235,6 @@ dependencies = [ "futures-task", "memchr", "pin-project-lite", - "pin-utils", "slab", ] @@ -299,9 +298,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.182" +version = "0.2.191" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" [[package]] name = "linux-raw-sys" @@ -323,13 +322,13 @@ checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" [[package]] name = "mio" -version = "1.1.1" +version = "1.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" +checksum = "1788edb87fdc09c7e26304471e2f5be8cdefb1b6930d6e3985fc02ff53bf86ee" dependencies = [ "libc", "wasi", - "windows-sys 0.61.2", + "windows-sys", ] [[package]] @@ -359,12 +358,6 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - [[package]] name = "proc-macro2" version = "1.0.106" @@ -406,7 +399,7 @@ checksum = "b7186006dcb21920990093f30e3dea63b7d6e977bf1256be20c3563a5db070da" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.115", ] [[package]] @@ -441,7 +434,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn", + "syn 2.0.115", ] [[package]] @@ -454,7 +447,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.61.2", + "windows-sys", ] [[package]] @@ -486,7 +479,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn", + "syn 2.0.115", ] [[package]] @@ -516,7 +509,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.115", ] [[package]] @@ -527,7 +520,7 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.115", ] [[package]] @@ -557,12 +550,12 @@ checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" [[package]] name = "socket2" -version = "0.6.2" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86f4aa3ad99f2088c990dfa82d367e19cb29268ed67c574d10d0a4bfe71f07e0" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" dependencies = [ "libc", - "windows-sys 0.60.2", + "windows-sys", ] [[package]] @@ -597,6 +590,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "3.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "tempfile" version = "3.27.0" @@ -607,7 +611,7 @@ dependencies = [ "getrandom", "once_cell", "rustix", - "windows-sys 0.61.2", + "windows-sys", ] [[package]] @@ -627,14 +631,14 @@ checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.115", ] [[package]] name = "tokio" -version = "1.49.0" +version = "1.54.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86" +checksum = "b52fd3255258d26fac7264ab5a76b53c13367136dc011d3d6ad4f8ed070396a3" dependencies = [ "bytes", "libc", @@ -642,18 +646,18 @@ dependencies = [ "pin-project-lite", "socket2", "tokio-macros", - "windows-sys 0.61.2", + "windows-sys", ] [[package]] name = "tokio-macros" -version = "2.6.0" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" +checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 3.0.10", ] [[package]] @@ -688,7 +692,7 @@ checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.115", ] [[package]] @@ -764,7 +768,7 @@ dependencies = [ "bumpalo", "proc-macro2", "quote", - "syn", + "syn 2.0.115", "wasm-bindgen-shared", ] @@ -798,7 +802,7 @@ checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.115", ] [[package]] @@ -809,7 +813,7 @@ checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.115", ] [[package]] @@ -836,15 +840,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "windows-sys" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" -dependencies = [ - "windows-targets", -] - [[package]] name = "windows-sys" version = "0.61.2" @@ -854,71 +849,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "windows-targets" -version = "0.53.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" -dependencies = [ - "windows-link", - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" - -[[package]] -name = "windows_i686_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" - -[[package]] -name = "windows_i686_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" - [[package]] name = "wit-bindgen" version = "0.51.0" diff --git a/Cargo.toml b/Cargo.toml index a365261..96cee79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,7 +77,7 @@ serde_json = "1" libc = "0.2" uuid = { version = "1", features = ["v4"] } rmcp = { version = "0.15", features = ["transport-io"], optional = true } -tokio = { version = "1", features = ["macros", "rt-multi-thread", "net", "time"], optional = true } +tokio = { version = "1.54", features = ["macros", "rt-multi-thread", "net", "time"], optional = true } schemars = { version = "1", optional = true } [dev-dependencies] diff --git a/deny.toml b/deny.toml index 1d6dee9..73ea5c0 100644 --- a/deny.toml +++ b/deny.toml @@ -24,6 +24,13 @@ ignore = [ # server transport is not compiled in. Mirrored in the `cargo audit` step # (.github/workflows/ci.yml). Revisit if an HTTP transport is ever added. "RUSTSEC-2026-0189", + # RUSTSEC-2026-0462: unbounded response-body buffering in rmcp's + # Streamable HTTP *clients* (`transport-streamable-http-client-reqwest`, + # `transport-streamable-http-client-unix-socket`). sudo-proxy is an MCP + # server over stdio and enables only `transport-io`, so neither client is + # compiled in. The fix is rmcp >= 3.9.0, a major-version jump tracked + # separately. Mirrored in the `cargo audit` step (.github/workflows/ci.yml). + "RUSTSEC-2026-0462", ] [bans] From 680600252fdf1ebd5b60bca4057cfe42e4e809f4 Mon Sep 17 00:00:00 2001 From: Cuihtlauac ALVARADO Date: Tue, 17 Nov 2026 19:52:27 +0100 Subject: [PATCH 5/5] ci(deny): ignore RUSTSEC-2026-0543 (chrono unmaintained) A new informational advisory marks every chrono version unmaintained, and deny.toml denies unmaintained crates, so the cargo deny job failed on every PR. chrono is pulled in only by the mcp feature: rmcp depends on it unconditionally and enables schemars' chrono04. rmcp 3.11 still requires it, so upgrading does not remove it. Ignore the advisory ID with a rationale in deny.toml and mirror it in the cargo audit step. A future chrono vulnerability advisory has its own ID and still fails the check. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Cuihtlauac ALVARADO (cherry picked from commit 4e3cca037f9a84062f1f34565d9c7f10b730249e) Signed-off-by: Cuihtlauac ALVARADO --- .github/workflows/ci.yml | 9 +++++---- deny.toml | 11 +++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 95c5769..21997e6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,10 +50,11 @@ jobs: - uses: taiki-e/install-action@v2 with: tool: cargo-audit - # RUSTSEC-2026-0189 ignored: DNS rebinding in rmcp's Streamable HTTP - # server transport, which sudo-proxy does not use (stdio only; see the - # documented rationale in deny.toml [advisories].ignore). - - run: cargo audit --ignore RUSTSEC-2026-0189 --ignore RUSTSEC-2026-0462 + # Ignores mirror deny.toml [advisories].ignore, which documents the + # rationale for each: 0189 and 0462 are rmcp HTTP-transport issues + # (sudo-proxy serves over stdio only); 0543 is chrono's unmaintained + # notice (pulled in by rmcp, no patched version). + - run: cargo audit --ignore RUSTSEC-2026-0189 --ignore RUSTSEC-2026-0462 --ignore RUSTSEC-2026-0543 deny: name: cargo deny diff --git a/deny.toml b/deny.toml index 73ea5c0..462c5be 100644 --- a/deny.toml +++ b/deny.toml @@ -31,6 +31,17 @@ ignore = [ # compiled in. The fix is rmcp >= 3.9.0, a major-version jump tracked # separately. Mirrored in the `cargo audit` step (.github/workflows/ci.yml). "RUSTSEC-2026-0462", + # RUSTSEC-2026-0543: chrono is unmaintained (informational; no + # vulnerability, no patched version). chrono comes in only through the + # `mcp` feature: rmcp depends on it unconditionally and enables schemars' + # `chrono04` feature. sudo-proxy never calls chrono itself, but rmcp does + # (the `DateTime` `last_modified` annotation, timeout-error + # formatting), so it cannot be dropped without forking rmcp — and rmcp + # 3.11 still requires it, so upgrading does not help. A future chrono + # *vulnerability* advisory has its own ID and still fails this check. + # Revisit when rmcp moves to jiff/time. Mirrored in the `cargo audit` step + # (.github/workflows/ci.yml). + "RUSTSEC-2026-0543", ] [bans]