Skip to content

Commit dc7ce02

Browse files
cuihtlauacclaude
andcommitted
Merge release/1.2.2 into main
Brings the GHSA-cpmp-67wf-gwmx fix to main, ported onto the plan executor, no-shell, audit and PTY harness code: - ttyguard startup check and --allow-injectable-tty (also forwarded with --host next to --no-shell); prompt warning line in write_request_header. - Unprivileged leaves in run_one get setsid (no controlling terminal); escalated leaves keep setpgid + the foreground hand-off. - MCP launcher scrubs the launcher's terminal variables. - New PTY test pty_injectable_tty.rs (PtyOpts gains `env`); docs incl. testing.md. Main's own #80 is kept: the release branch's backport (b196b68) is superseded, and the dependency commits were already on main. Version 1.2.2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Cuihtlauac ALVARADO <cuihtlauac@tarides.com>
2 parents 061ed36 + 6806002 commit dc7ce02

23 files changed

Lines changed: 837 additions & 25 deletions

‎.claude-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sudo-proxy",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"description": "Run privileged commands locally or over SSH, with a human keypress approving each one",
55
"author": {
66
"name": "Tarides"

‎Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sudo-proxy"
3-
version = "1.2.1"
3+
version = "1.2.2"
44
edition = "2021"
55
license = "MIT"
66
description = "Privileged command execution proxy with human approval via pkexec or sudo"

‎README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ key ID `A6F84B53410B83FB`) before installing; a missing or bad signature
135135
aborts the install. Prefer `cargo install` if you'd rather build from
136136
source.
137137

138+
The daemon must run in a terminal window that no other process can type into:
139+
outside tmux/screen, on Wayland. It refuses to start otherwise; see
140+
[Where to run the daemon](docs/usage.md#where-to-run-the-daemon).
141+
138142
Point your MCP client at the server — add to the project's `.mcp.json` or
139143
`~/.claude/claude_desktop_config.json`:
140144

‎changelog.md‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,87 @@ resolved path that `env` receives. Regressions: unit tests in `executor`, and
129129
`resolves_line_names_the_binary_that_runs` in `tests/pty_e2e.rs`, which follows
130130
the issue's repro.
131131

132+
## v1.2.2 — 2026-11-21 (security release)
133+
134+
A patch release on top of v1.2.1 with one security fix and one backported
135+
fix, and nothing else (main's 1.3 work is not included):
136+
137+
- **GHSA-cpmp-67wf-gwmx** (high): the daemon refuses to start in a terminal
138+
that other same-UID processes can type into (tmux/screen, kitty/WezTerm/
139+
Konsole remote control, X11, …), unless started with
140+
`--allow-injectable-tty`. Unprivileged children no longer share its
141+
controlling terminal.
142+
- **#62** (backport of #80): the `Resolves:` line names the binary that
143+
actually runs.
144+
145+
**Upgrade note:** if you start the daemon inside tmux/screen or on X11, it now
146+
refuses with an explanation; move it to a terminal of its own on Wayland, or
147+
pass `--allow-injectable-tty`. With `--host`, upgrade the remote first if you
148+
use the override, since a 1.2.1 remote rejects the forwarded flag.
149+
150+
### Refuse approval terminals other processes can type into (GHSA-cpmp-67wf-gwmx)
151+
152+
The daemon approves a request by reading one key from its terminal, and it
153+
cannot tell a key the human typed from one injected by another process running
154+
as the same user. The usual requester, an AI agent, also has a same-UID shell.
155+
In tmux or screen (`send-keys`, `stuff`), in a terminal with remote control
156+
(kitty, WezTerm, Konsole's D-Bus `sendText`), or in any X11 session
157+
(`xdotool key y`), it could send a privileged request and answer `y` to its own
158+
prompt, or `a` to grant itself the session.
159+
160+
- The daemon now checks its terminal at startup (`src/ttyguard.rs`). If it
161+
finds one of these, it prints each reason and refuses to start. Covered:
162+
multiplexer `TERM` or `$TMUX`/`$STY`/`$ZELLIJ`; kitty, WezTerm, Konsole,
163+
VS Code and Emacs terminals; X11 without Wayland. `--allow-injectable-tty`
164+
starts it anyway, with a warning line in every prompt. There is deliberately
165+
no `hosts.json` equivalent: an agent can write that file and restart the
166+
daemon through MCP. `--pkexec` skips the check, since privileged approval
167+
then happens in polkit's dialog.
168+
- With `--host`, the local terminal is checked before ssh starts, and the
169+
override is forwarded to the remote daemon. A remote older than 1.2.2
170+
rejects the flag and exits, which fails closed.
171+
- Unprivileged children now run in their own session, with no controlling
172+
terminal, so a command (or a background job it leaves) cannot `TIOCSTI`
173+
keystrokes into a later prompt. A kernel that still allows `TIOCSTI` is
174+
reported as a warning.
175+
- `sudo-proxy-mcp` removes the launcher's own terminal variables (`TMUX`,
176+
`KITTY_*`, …) from the window it spawns, so a fresh window is not refused for
177+
the agent's tmux. If the daemon refuses, the window stays open until Enter,
178+
and the `start_server` error explains what to do.
179+
- Docs: threat-model B3 row and attack-tree leaf 3.5 with residuals,
180+
assurance-case assumption A1, security/usage/install/README.
181+
182+
Residuals: an XWayland terminal inside a Wayland session, emulators the check
183+
does not know, and X11 synthetic input into the polkit dialog under `--pkexec`.
184+
The structural fix is to run the agent as a separate Unix user.
185+
186+
### The `Resolves:` line names the binary that actually runs (#62, backport of #80)
187+
188+
The prompt resolved `argv[0]` on the daemon's own PATH, but the executor
189+
spawned the bare name with a cleared environment, so the child searched the
190+
default login PATH (sudo searched its `secure_path`, pkexec's `sh -c` the login
191+
PATH). A daemon started from a dev shell (Nix, virtualenv, `~/.local/bin`)
192+
could show one file and run another, or show a file and then fail with ENOENT.
193+
194+
`executor::resolve_command` now resolves argv[0] on the child's PATH, and a
195+
name containing `/` against the child's working directory `/`. The TUI and GUI
196+
prompts display that result, and every spawn path uses it: directly (keeping
197+
the requested `argv[0]`), as the program after `sudo` / `pkexec`, and in the
198+
multi-stage pkexec `sh -c` string. A name that does not resolve is refused with
199+
`command not found: <name>` instead of being looked up a second time; in a
200+
pipeline, before any stage is spawned. The GUI dialog now also shows
201+
`(not found in PATH)`. As in 1.2.1, the TUI shows the `Resolves:` line for the
202+
first stage and a warning for later stages that do not resolve.
203+
204+
Behaviour change: a privileged command found only on sudo's `secure_path` (e.g.
205+
`/snap/bin`) but not on the default login PATH is now refused, where it
206+
previously ran under a mismatched prompt.
207+
208+
This re-applies the fix from main (#80) to the 1.2 pipeline executor; the code
209+
differs because 1.2 predates structured plans. Regressions: unit tests in
210+
`executor` and `exec_direct_spawns_resolved_path_keeping_argv0` in
211+
`tests/exec.rs`.
212+
132213
## v1.2.1 — 2026-11-18 (security release)
133214

134215
A patch release on top of v1.2.0 with two security fixes and nothing else:

‎docs/assurance-case.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ asserted, evidence not yet produced).
6666
|------|------|-----------|
6767
| **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. |
6868
| **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).) |
69-
| **A1** | Assumption | `/dev/tty` is trusted: what the daemon writes is what the human sees, and the keypress read is the human's. |
69+
| **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. |
7070
| **A2** | Assumption | `sudo` (and `pkexec`) correctly enforce escalation and `env_reset`; the kernel enforces socket permissions and `SO_PEERCRED`. |
7171
| **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). |
7272
| **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. |

‎docs/install.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ sudo pkexec-cache --create
6363

6464
Then configure your MCP client — see [MCP server](mcp.md).
6565

66+
The daemon refuses to start in a terminal other processes can type into (tmux,
67+
screen, X11, kitty/WezTerm remote control, …). Run it in a terminal window of
68+
its own on Wayland; see [Where to run the daemon](usage.md#where-to-run-the-daemon).
69+
6670
## Building locally
6771

6872
```bash

‎docs/security.md‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,31 @@ the user during TUI approval.
3838

3939
**Execution isolation:** child processes run with cwd `/`, umask 0077, and
4040
stdout/stderr piped — they do not inherit the socket file descriptor. stdin is
41-
null except for sudo mode, which inherits the terminal so sudo can prompt for a
42-
password.
41+
null. Privileged children (sudo, pkexec) stay in the daemon's session so sudo
42+
can open the terminal for its password prompt. Unprivileged children run in a
43+
session of their own, with **no controlling terminal**, so they cannot inject
44+
keystrokes into the approval prompt with `TIOCSTI` (GHSA-cpmp-67wf-gwmx).
45+
46+
**Approval terminal (GHSA-cpmp-67wf-gwmx):** the prompt cannot tell a key the
47+
human typed from one another process running as the same user injected, and
48+
an AI requester typically has a same-UID shell. So the daemon refuses to start
49+
in a terminal that accepts synthetic input from other processes:
50+
51+
- tmux, GNU screen, zellij (`TERM`, `$TMUX`, `$STY`, `$ZELLIJ`);
52+
- kitty, WezTerm, Konsole (remote control), VS Code's integrated terminal,
53+
Emacs terminals;
54+
- any terminal in an X11 session (XTEST, e.g. `xdotool key y`).
55+
56+
It prints each reason and exits. Run it in a terminal window of its own, on
57+
Wayland (GNOME Terminal, foot, Alacritty, …). `sudo-proxy --allow-injectable-tty`
58+
starts it anyway, and every prompt then carries a warning line. The override
59+
has no `hosts.json` equivalent because an agent can write that file:
60+
whoever starts the daemon decides. A kernel that still allows `TIOCSTI`
61+
(`dev.tty.legacy_tiocsti`, or no such sysctl before 6.2) is reported as a
62+
warning. Detection is best effort; see the residuals in
63+
[threat-model.md](threat-model.md#coverage-and-residuals). The strongest
64+
setup is to run the agent as a **separate Unix user**, or in a sandbox without
65+
access to your display or your multiplexer's socket.
4366

4467
**TUI hardening:** the Y/N prompt reads a single keypress in non-canonical
4568
terminal mode (no Enter required) and times out after 60 seconds (default deny).

‎docs/testing.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ cargo build --release
2929
./target/release/sudo-proxy -v --socket /tmp/sp-test.sock
3030
```
3131

32+
Terminal A must be a window of its own, outside tmux/screen and on Wayland:
33+
the daemon refuses a terminal other processes can type into
34+
(GHSA-cpmp-67wf-gwmx). To test inside tmux anyway, add
35+
`--allow-injectable-tty`; every prompt then shows a warning line.
36+
3237
**Terminal B — send requests** with the freshly built client:
3338

3439
```bash

‎docs/threat-model.md‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ invariant at a given boundary are omitted.
7474
| 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 |
7575
| DoS | Operator never answers, leaving the gate open. | 60 s timeout, default **deny**. | G5.2 |
7676
| Elevation | Social-engineer the human into approving. | Covered by G4; residual printable-range look-alikes accepted. | G4.4 (residual) |
77+
| 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 |
7778

7879
### B4 — daemon → exec → root (A1)
7980

@@ -136,8 +137,12 @@ A A root command runs that the human did NOT approve
136137
│ │ [resolved path + "-> target" shown → G4.2 · blocked]
137138
│ ├─ 3.3 Push the real command / [y/N] off-screen with a huge arg
138139
│ │ [length bound + hidden-bytes marker → G4.3 / F3 · blocked]
139-
│ └─ 3.4 Printable-range Unicode look-alike / NBSP in reason
140-
│ [cannot hide the real command → G4.4 · residual (accepted)]
140+
│ ├─ 3.4 Printable-range Unicode look-alike / NBSP in reason
141+
│ │ [cannot hide the real command → G4.4 · residual (accepted)]
142+
│ └─ 3.5 Answer the prompt without the human: inject `y` into the TTY
143+
│ [startup refusal of injectable terminals; children without a
144+
│ controlling tty → A1 / GHSA-cpmp-67wf-gwmx
145+
│ · blocked for detected terminals (residual: undetected ones)]
141146
│
142147
└─ 4 Execute around the gate entirely (defeat G5 / G6)
143148
├─ 4.1 Direct same-UID socket client bypassing MCP validate_host
@@ -167,6 +172,18 @@ is unaccounted for. The residuals — already on record and accepted — are:
167172
- **loopback self-routing (F5, closed).** `is_local_host` normalizes self/loopback
168173
targets; residual undetected aliases are covered by the C10 composition (every
169174
remote daemon still gates unattended exec). See finding F5.
175+
- **3.5 — keystroke injection into the approval terminal
176+
(GHSA-cpmp-67wf-gwmx).** Detection reads environment variables and one sysctl,
177+
so it is best effort. It does not see an XWayland terminal (e.g. `xterm`)
178+
inside a Wayland session, an emulator with remote control it does not know,
179+
or a process that shares the daemon's controlling terminal on a kernel that
180+
still allows `TIOCSTI`. Nor does it cover `--pkexec`, whose polkit dialog has
181+
X11's own synthetic-input exposure, or a daemon the operator started with
182+
`--allow-injectable-tty`. An agent can always start a daemon of its own in a
183+
terminal it controls; that daemon's `sudo` then has no cached credential for
184+
the new terminal and asks for the password. The structural fix is to run the
185+
agent as a separate Unix user, or in a sandbox without access to the display
186+
or the multiplexer's socket.
170187
- **3.4 — look-alike `reason` (F1 residual).** Printable Unicode can mislead but
171188
cannot conceal the real command line, which is printed separately.
172189
- **4.2 — SSH first-contact MITM (assumption A4).** The ssh invocation sets no

0 commit comments

Comments
 (0)