Skip to content

Close six holes a review found: aliases, find, wrappers, deep code, long patterns, canonical names - #291

Merged
camiloazula merged 6 commits into
mainfrom
fix/review-findings
Nov 7, 2026
Merged

camiloazula merged 6 commits into
mainfrom
fix/review-findings

Conversation

@camiloazula

Copy link
Copy Markdown
Owner

A full review of the workspace found six bugs, five of them a line judged safe or a crafted line that took seconds. Each is fixed in its own commit, with the case lines that were judged wrong.

Not changed, on purpose: hash -p /tmp/x ls; ls stays safe in classify, as PATH=/tmp ls does, since the guard judges a bare name by its name.

The fixes were reviewed twice by an independent reviewer. The first pass found five gaps: the **/ shape was still quadratic, man had other option spellings, the ? direction of canonical matching was missing, the alias fix dropped the aliases defined in full beside the unread one, and bwrap's --level-prefix was misread. All five are fixed here, and the second pass found nothing new.

just verify

Every recipe passes on the last commit, and each earlier commit passes clippy on its own.

cargo fmt --all --check
cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
cargo llvm-cov --no-clean --workspace --all-features --locked --fail-under-lines 90
cargo test --release --locked --all-features -p milo-guards-shell --test timing
cargo test --release --locked --all-features -p milo-guards-secrets --test timing
cargo test --doc --workspace --all-features --locked
RUSTDOCFLAGS="-D warnings" cargo doc --workspace --all-features --no-deps --locked
cargo clippy -p milo-guards-shell --no-default-features --all-targets --locked -- -D warnings
cargo test -p milo-guards-shell --no-default-features --test inline_off --locked
cargo deny check bans licenses sources

675 tests passed, 0 failed; line coverage 96.59% (floor 90%); bans ok, licenses ok, sources ok

A word of `alias` holding an expansion (`alias x="$CMD"`, `alias
x="$(curl …)"`) was dropped from the aliases the line defines, so a later
call of it resolved to an unknown bare name and the line was safe. Such a
word may define any alias with any value, so the definition is a script
the guard does not read: it is `unknown`, as `eval "$CMD"` is. The aliases
the same command defines in full are still read, so a call of one is
judged by what it runs.

Fixes #285
`find`'s own actions that write a file were never read by the rules, so
`find . -fprint ~/.bashrc` and `find . -fprintf /etc/cron.d/x '…'` were
safe while `find . > ~/.bashrc` is `overwrite`; `effect` already called
them writes. Each file is now judged as a redirect's is, read from the
expression as `find` reads it, so a test's value and the words an `-exec`
runs are not taken for one.

Fixes #287
`firejail`, `fakeroot`, `faketime`, `bwrap`, `proot` and `entr` run the
command after their options, but none was a wrapper the guard knew, so
`firejail rm -rf ~` was safe while `nice rm -rf ~` is a delete. Each now
runs its tail, read past its own options. bubblewrap and proot map the
file system the command sees, so a path it names may be any folder: the
command is judged as written and the line is unreadable as well.

`man -P CMD`, `man -H CMD` and fzf's `--preview CMD` hand a command to a
shell, which is read as a script; man's short options are read as getopt
bundles them (`-aP CMD`). A key binding of fzf may run any command, which
is not read.

Fixes #288
`read` stops at the first node past `MAX_TREE_DEPTH` and says `deep`, but
`understand` walked the whole tree with no limit, so code nested past it
came back `Understood` with the acts after the deep part missing. The
strict reader now refuses a node past the same depth, so `deep` code is
never understood, which the crate promises. The shell guard was not fooled,
since it reads `deep` too, but any other caller would have been.

`tests/robust.rs` now holds the 2 000-deep case to `NotUnderstood`, and
holds every deep shape the reader does not walk whole to it as well.

Fixes #289
Whether a pattern can pick a file a tool runs on its own was asked once for
every part the pattern may start at, each time in time linear in the
pattern, so `cp x src/a*/a*/…/x` with a 6 KB operand took 6.7 s and a
`**/` run of 60 KB took 15 s, though every input is within the limits.
`picks` builds its table from the end of the pattern, so one table now
answers every start, and the check that the rest is all globstars is kept
as the table is built. The same lines take tens of milliseconds.

The shell guard's timing tests hold the `a*/` and `**/` shapes to linear
time, and `tests/posix_wildcards.rs` pins their answers in every build.

Fixes #286
Core compared names character by character, so a protected folder named
`café` was missed as `cafe` plus a combining accent, the spelling HFS+
keeps on disk; APFS and HFS+ open both as one file. The home directory,
the sensitive places and the protected paths now compare by canonical
equivalence, with Unicode 17.0's decompositions and combining classes in
`src/canonical.rs`, and a pattern matches either spelling (`caf?` picks
`café` both ways). Every place that reads this fails closed on a match too
many; the workspace still compares as spelled.

The file guard had pinned the old answer as a limit; its case moves to
`tests/cases/protected.cases` with `write_protected`, and the design pages
say how names compare.

Fixes #290
@camiloazula
camiloazula merged commit e40f5e1 into main Nov 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment