Skip to content
Open
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e75eabc
[RSI, security] Refuse sudo/doas privilege escalation in kernel bash
sethkarten Sep 16, 2026
0acb8dc
fix(runtime): close sudo-guard quoting, wrapper, stdin, and alias byp…
sethkarten Sep 17, 2026
716d825
fix(runtime): judge bundled wrapper flags and cap brace expansion in …
sethkarten Sep 17, 2026
35de5ca
fix(runtime): gate heredoc runners on the sudo guard command-word walk
sethkarten Sep 17, 2026
f39a9de
fix(runtime): treat alias bodies that name a runner as runners in the…
sethkarten Sep 17, 2026
526598b
fix(runtime): resolve alias bodies through the sudo guard walk
sethkarten Sep 17, 2026
e3d6268
fix(runtime): close brace, launcher, here-string, and syntax bypasses…
sethkarten Sep 17, 2026
2e77d95
fix(runtime): correct launcher options and glued here-string payloads…
sethkarten Sep 17, 2026
c8d4358
fix(runtime): take the value options strace, ltrace, and systemd-run …
sethkarten Sep 17, 2026
2b16707
fix(runtime): encode launcher value options from their synopses and s…
sethkarten Sep 17, 2026
dd7e35f
fix(runtime): complete the launcher option tables and judge plain com…
sethkarten Sep 17, 2026
18e24f6
docs(changeset): name the option-abbreviation gap in the sudo guard's…
sethkarten Sep 17, 2026
69dd9bf
fix(runtime): judge `time` flags and read glued -c payloads only from…
sethkarten Sep 17, 2026
56242ef
fix(runtime): read POSIX classes in the sudo guard's glob patterns
sethkarten Sep 17, 2026
30b4670
fix(runtime): read bracket negation before expanding POSIX classes
sethkarten Sep 17, 2026
e457c68
fix(runtime): resolve `hash -p` command-hash entries in the sudo guard
sethkarten Sep 17, 2026
72bd9dc
fix(runtime): read every `hash -p` spelling and re-walk registered ta…
sethkarten Sep 17, 2026
8015f8d
fix(runtime): close the hash-shadowing and float-duration bypasses
sethkarten Sep 17, 2026
9963831
fix(runtime): keep hash registrations from hiding builtins, patterns,…
sethkarten Sep 17, 2026
41d4030
fix(runtime): judge registered wrappers twice, coproc names, nested a…
sethkarten Sep 17, 2026
cf66036
fix(runtime): fail closed when an alias chain outruns the scan depth
sethkarten Sep 17, 2026
1755058
Merge origin/main into cb-fix-sudo-guard: keep the sudo guard and mai…
Sep 18, 2026
f0ff2bc
Merge branch 'main' into cb-fix-sudo-guard
sethkarten Sep 18, 2026
ab506c5
Merge branch 'main' into cb-fix-sudo-guard
sethkarten Sep 20, 2026
2af8c06
Merge branch 'main' into cb-fix-sudo-guard
sethkarten Sep 21, 2026
aed1bfb
Merge branch 'main' into cb-fix-sudo-guard
sethkarten Sep 21, 2026
4aff3b9
Merge branch 'main' into cb-fix-sudo-guard
sethkarten Sep 21, 2026
6fa799c
Merge branch 'main' into cb-fix-sudo-guard
sethkarten Sep 22, 2026
6fcf5f8
fix(runtime): align _matching_paren with the guard family and pin one…
sethkarten Sep 22, 2026
44f501f
Merge branch 'main' into cb-fix-sudo-guard
sethkarten Sep 22, 2026
fd88b1d
Merge branch 'main' into cb-fix-sudo-guard
sethkarten Sep 22, 2026
612ac63
Merge branch 'main' into cb-fix-sudo-guard
sethkarten Sep 23, 2026
4d14983
Merge branch 'main' into cb-fix-sudo-guard
sethkarten Sep 23, 2026
2b0a7bb
Merge branch 'main' into cb-fix-sudo-guard
sethkarten Sep 23, 2026
ef187be
Merge branch 'main' into cb-fix-sudo-guard
sethkarten Sep 23, 2026
c1ffe19
Merge branch 'main' into cb-fix-sudo-guard
sethkarten Sep 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/coding-agent/.changes/kernel-sudo-guard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added a privilege-escalation guard to the kernel bash tool: sudo/doas command words are refused before any process starts, because silent privilege escalation outranks every other guard on passwordless-sudo setups. Covered: any path spelling, quote- and escape-folded spellings (`su"do"`, `"sudo"`, ANSI-C `$'su\x64o'` with out-of-range escapes kept literal instead of raising), brace/glob/letter obfuscation of the command word (`su{d,}o`, `{sudo,} id`, `sud[o]`, `su?do`, sequences such as `s{u..u}do` or `{1..9}`), and a brace group whose element count times the group chain exceeds the enumeration cap fails closed before it is built, wrapper chains (env/nice/timeout/nohup/setsid/exec/busybox/stdbuf/ionice/strace/ltrace/watch/faketime/systemd-run/chroot, including their value-taking options such as `env -S`, `env -C`, `timeout -s`, `stdbuf -o`, `nice -n`, `exec -a`, `watch -n` (its `-d`/`-t` and `faketime`'s `-m`/`-f` are boolean), each launcher's required-argument long options (strace's `--user`/`--argv0`/`--color` and the rest of its longopts, ltrace's `--indent`/`--library`, systemd-run's `-H`/`--uid`/`--gid` and its timer and property options, parallel's `-C`/`-d`/`-J`/`-P`/`-s`/`-E` and their long forms, `env -a`/`--argv0` and BSD `env -P`, `watch -q`/`-s`), bundled short flags such as `env -vu NAME`, and the operands of xargs options such as `-n`, `-I`, `-P`, plus the leading operands of `chroot`/`faketime` and `timeout`'s integer, floating-point, and suffixed durations), assignment prefixes, redirections, group/subshell/brace, `coproc`, and compound-command positions (`if`/`then`/`elif`/`else`/`while`/`until`/`for`/`do`/`case` bodies, with `for`/`select` loop variables and `case` subjects and labels read as syntax rather than commands, and `time`'s own flags skipped so `time -p sudo id` still reaches the command word), pipelines (`echo x | sudo tee /etc/hosts`), xargs and `parallel` operands and option operands (judged fail-closed because BSD and GNU disagree on which operands are optional), `find -exec`/`-execdir`/`-ok`/`-okdir` and `fd -x`/`-X` commands, alias bodies and `hash -p` command-hash entries in every spelling (a registered name scans as the command it runs, shell builtins such as `eval`/`command`/`exec` keep their own meaning because the hash table cannot shadow them, the word's own spelling is judged as well so `hash -r` cannot hide it, and an entry built from expansion is refused because the command it hides cannot be resolved), interpreter payloads (`sh -c`, bundled `-ce`, and glued payloads only from short bundles, so `bash --rcfile FILE -c 'sudo id'` is refused, `eval`), quoted `$(...)` spans (matched quote-aware, so `echo "$(printf ')'; sudo id)"` is refused), backticks, process substitutions (`<(cmd)`, `>(cmd)`) including a runner's script source, here-strings (`bash <<< 'sudo id'`, `bash<<<'sudo id'`, and glued multi-token payloads such as `bash<<<'sh -c "sudo id"'`, whose quoted target the tokenizer keeps as one word), and heredoc bodies owned by a shell or piped to one in the same text (the gate reuses the guard's own command-word walk, so `command`, `command -p`, `command --`, wrapper chains, xargs operands, and `find -exec`/`-execdir` operands are all treated as shell runners, while a `command -v`/`-V` lookup or a plain operand mention is not; an alias whose body reaches a runner (wrapper chains such as `env sh`, `command sh`, or `xargs -I{} sh -c {}` included) counts as a runner for the same gate and for the script-source scan). Lookup forms (`command -v sudo`, `command -V sudo`, `which sudo`) stay allowed, and `command` itself stays gated to those lookup flags instead of short-circuiting the walk, so `command sudo id` is refused; operand mentions (`man sudo`, `grep sudo file`), data heredocs, and comments stay allowed; unresolvable command-position words carrying a sudo/doas mention (`$CMD id`, `$SUDO id`) fail closed, while a name assembled so that no such spelling appears (a `printf` with hex escapes, a base64 payload piped to a shell) stays out of a name-based scan's reach, as do payloads nested deeper than the scan follows. Out of scope: `su`, trap actions, other interpreters' string payloads (`python -c`), Windows runas, script-file contents, launchers outside the modeled set that pick their own program or domain (`ssh`, `script` with its diverging util-linux and BSD option shapes, package runners such as `dx`/`npx`), and make recipes. Explicit bypasses: `bash(command, allow_sudo=True)` or `PI_BASH_ALLOW_SUDO=1`, where the environment bypass is frozen at kernel start so mid-session `os.environ` writes cannot neuter the guard; they are ignored and warned about loudly. It is a foot-gun guard, not a sandbox: an unmodeled launcher or value option, an abbreviated long option (`strace --verb 5 sudo id`), a renamed or copied tool at another path (a symlink to the tool and a plain copy both run the real binary, and `realpath` cannot see a copy), or an extglob spelling such as `s@(u|x)do` with `shopt -s extglob` on (the tokenizer splits the group, and shell-option state is not statically knowable), can still hide a command word, and `su`, other interpreters' string payloads, script files, and those bypasses all still reach root. A name that merely contains `sudo` is judged by its case-folded basename, so `sudoku`, `sudo-report`, and `s-u-d-o` stay runnable while `SUDO` still is the tool on a case-insensitive filesystem; a glob in the basename is judged as a pattern (`/usr/bin/su*` refuses), and a word that carries quoting or expansion still falls back to its letters. The launcher tables name only options their tool really has, because an entry for a phantom option swallows the command word. A glob pattern that can match `sudo`/`doas` is read as a pattern, POSIX classes included, so `[[:lower:]]udo` and `[[:alpha:]]udo` refuse exactly like `sud[o]` and `su?do`, while a spelling that cannot match either name (`s[[:upper:]]do`, `[[:digit:]]udo`, `[![:lower:]]udo`) stays allowed. Known measured cost, accepted for this pass and named as the follow-up: a command carrying many heredocs is resolved quadratically, because each heredoc scans the remaining text for its delimiter and then sweeps the words to mark the body as data. Measured on this module: 0.066s at 1000 heredocs and 1.34s at 5000 (about 100 KB of command text), reproduced by timing `_apply_heredocs` alone, and extrapolating to a command near the argv limit gives minutes. The fix is a single sweep over the collected body ranges; it is not taken here because it changes the scan machinery rather than closing a bypass.
Loading
Loading