Repository navigation
Minor Changes
-
949dc85Thanks @tufantunc! - The classifier now finds the program an interpreter is handed when options stand between the interpreter and the program. A shell's-cis a switch, so its program is the first operand wherever-cstands:sh -c -- CMD,sh -c -e CMD,sh -o errexit -c CMDandbash --rcfile FILE -c CMDare classified, and checked against the never-allowed list, asCMD. For the other interpreters the classifier knows the options that take no value and takes every other option to have one, so an option's value no longer hides the program flag behind it (python3 -W ignore -c CODE,perl -I lib -e CODE,node -r ./x -e CODE,ruby -r json -e CODE,php -d a=b -r CODE,lua -l os -e CODE,osascript -l JavaScript -e CODE), nor does a cluster of flags (perl -lane CODE) or a program attached to its flag (perl -e'CODE').vim,vi,ex,view,nvimandgdbare read with their options after operands too (vim FILE -c CMD,gdb PROG -ex CMD), and vim's+CMDis read as-c CMD. This reading applies behind a command the classifier has no table entry for as well (unshare -m sh -c -- CMD,docker exec NAME python3 -W ignore -c CODE). Before, each of these wassafe.More names are read as interpreters: a version after the name (
python3.11,perl5.36,php8.2,lua5.4,ksh93),mksh,pdksh,oksh,yash,rbash,posh,fish,csh,tcsh,nodejs,pypy,pypy3,jruby,luajit,nvim,rvim,rview,gviewandgdb-multiarch. More program flags are read:php -B,-R,-Eand--run,bun --eval,-pand--print, and gdb's-eval-command,-iex,-eiexand their abbreviations with one dash or two.Upgrade notes:
- The invocations above that ran without a prompt now follow the policy for a program handed to an interpreter:
destructivefor code the classifier does not read, and the class of the command itself for a shell's-c. - An interpreter option the classifier does not know is taken to have a value.
python3 --some-new-flag run.py -c config.ymlis then read as-chandingconfig.ymlto python and isdestructive; with an option it knows (python3 -u run.py -c config.yml) the line keeps its class. Report such an option and it is added. vim +q FILE,ex -s +'%s/a/b/' +wq FILEand any other+COMMANDaredestructive, and so is a+/PATTERNthat holds a|.vim +10 FILE,vim + FILEandvim +/pattern FILEkeep their class.fish -c CMD,csh -c CMDandtcsh -c CMDaredestructiveat least: their program is not read as POSIX shell text.- A script's own arguments are not read:
python3 -u train.py -c config.yml,python3 -m gunicorn -c conf.py appandnode server.js -p 3000keep their class.
- The invocations above that ran without a prompt now follow the policy for a program handed to an interpreter:
-
949dc85Thanks @tufantunc! - The command classifier now reads the shell's own grammar. A command inside a subshell or a brace group, in anif, loop orcaseblock, in a function body, next to a redirection, in atrapaction, behindbuiltin,coprocortime, in zsh'srepeat,foreachand short loop forms, inside=(…)or${ …; }, in a$(…)that holds a quoted parenthesis, or fed to a shell as a here-string or through a pipe into a group is classified, and checked against the never-allowed list, as the command it runs. Before, most of these were classified by a word that names no program and came outsafe.Upgrade notes:
- Commands of these shapes that ran without a prompt now follow the policy for the command inside them.
(sudo id)andif true; then sudo id; fiareprivileged, and{ reboot; }is refused, exactly assudo idandrebootare when sent on their own. Commands whose grammar holds nothing elevating or destructive keep their class:( cd /srv && ls ),for f in *.log; do wc -l "$f"; done,{ date; uptime; } > out.txt. - A command word that the shell rewrites before running it, a glob or a brace expansion such as
./run-*.shor/opt/app-{a,b}/bin/start, is nowdestructive: the name of what runs is not in the command. Write the name out. (( … ))is read as commands, becausedashruns it as a subshell.(( $n > 5 ))and(( count*2 > 10 ))are nowdestructive;(( n > 5 ))and[ $((count*2)) -gt 10 ]keep their class.- A word that names an elevating or never-allowed command is read as that command wherever some shell would run it: a
caselabel after the first (case $1 in start) …;; reboot) …;; esac), an array element (x=(sudo reboot)). Name the label differently, or build the array from a file. - A line with a
$(…)that holds acasestatement (ended byesac, or by a}as zsh allows) isdestructiveat least, because shells do not agree on where such a substitution ends and nothing behind it is known to be data. The same holds for acasestatement anywhere behind a$(, a backquote or a process substitution on the line (echo "$(date)"; case "$1" in …): whether it stands inside is what cannot be told.v="$(case "$1" in start) echo up ;; esac)"; echo "$v"now asks for approval. Assign from acasestatement instead (case "$1" in start) v=up ;; esac; echo "$v"), which keeps its class. The text from the substitution to the line's last)is still read by command name with quotes ignored, sov="$(case $1 in a) echo 1 ;; esac)"; echo "run (sudo make install) first"isprivileged. - A line nested so deep that the classifier stops reading it (eight levels of substitutions, groups and carriers, counted along every way it reads the line) is
privileged. This held for the class before; it now holds for the never-allowed scan too, which could stop first. - A word that starts with a bracket expression is a glob to a POSIX shell, so a PowerShell cast as the first word (
[xml](Get-Content web.config),[int]"5") is nowdestructive. A static member ([math]::Round(1.5)) keeps its class. - A PowerShell condition or block that starts with a variable,
if ($x -gt 5) { … }orif (Test-Path $p) { $c = Get-Content $p }, is nowdestructive.if (Test-Path $p) { Remove-Item $p }keeps its class.
- Commands of these shapes that ran without a prompt now follow the policy for the command inside them.
-
949dc85Thanks @tufantunc! -split --filter=COMMAND(GNU coreutils, also installed asgsplit) is now read as a carrier: the command it hands tosh -cis classified whatever its shape, in every spellingsplitaccepts — attached or detached, under any prefix from--fup. The command is at leastdestructive,privilegedwhen the filter elevates, and the never-allowed list applies to the filter.Upgrade note: a
split --filtercommand that ran assafeis now asked for approval, or refused, depending on the role and tier.
Security
- Fixed GHSA-hmrp-r5wm-5mqf: a command inside the shell's own grammar (a subshell, a brace group, after a reserved word, behind a redirection) or behind an interpreter's options (
sh -c -- CMD,python3 -W ignore -c CODE) reached classsafe, with no never-allowed match. - Fixed GHSA-gpfp-xjq7-64hv:
split --filter=COMMANDreached classsafewhen the filter held no space, with no never-allowed match. Reported by @chrispham-cyber.