Skip to content

Deny find's -exec/-execdir/-ok/-okdir/-delete regardless of allowlist - #1

Merged
DavidLiedle merged 1 commit into
devrelopers:mainfrom
holistis:fix/exclude-find-exec-from-default-allowlist
Sep 18, 2026
Merged

DavidLiedle merged 1 commit into
devrelopers:mainfrom
holistis:fix/exclude-find-exec-from-default-allowlist

Conversation

@holistis

@holistis holistis commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The default platform_defaults() read-only allowlist (src/allowlist.rs) includes find **, which, per the documented glob semantics, matches every token after find, including find's own action flags.

find . -exec sh -c '...' + runs an arbitrary program once per matched file (or once per batch, for the +-terminated form), independent of and unaffected by any allowlist rule for find itself. Execution goes straight to argv (no shell), so this is not a shell-metacharacter problem: -exec's own +-terminated form has no ; in it, so it is not caught by the existing check_metacharacters pass either.

Fix

Adds -exec, -execdir, -ok, -okdir, and -delete as single-token entries to the existing hard denylist in src/safety.rs (checked before allowlist matching, per this module's own documented design: "a hard denylist of token patterns that no allowlist can re-enable"). Single tokens rather than a two-token ["find", "-exec"] sequence, so the rejection also catches the realistic case where other predicates sit between find and the action flag, e.g. find /tmp -type f -exec rm {} +.

Tests

Added two regression tests:

  • find_exec_family_is_always_denied_even_with_predicates_between, using the +-terminated form specifically, to prove the rejection does not merely piggyback on the existing semicolon check.
  • find_ok_family_is_denied_defense_in_depth, for -ok/-okdir (these only support the ;-terminated form, so they're already caught earlier by check_metacharacters today; the denylist entries are belt-and-suspenders in case that changes).
  • plain_find_without_action_flags_is_not_denied_by_hard_denylist, confirming ordinary find usage is unaffected.

Ran the full suite locally (cargo test --lib, GNU toolchain): 31 passed, 0 failed, including the new ones above.

If this is useful, a mention or link back to my GitHub profile (github.com/holistis) would be appreciated.

…wlist

The default read-only allowlist includes "find **", which matches every
argument after find, including find's own action flags. find . -exec
sh -c '...' + runs an arbitrary program per matched file, independent
of the allowlisted command itself, and does not require a shell
metacharacter (the +-terminated form has no ; in it).

Adds these as single-token entries to the existing hard denylist
(checked before allowlist matching, per this module's own documented
design) rather than a two-token "find -exec" sequence, so the rejection
also catches the realistic case where other predicates sit between find
and the action flag, e.g. find /tmp -type f -exec rm {} +.

Adds regression tests for the +-terminated bypass specifically (proving
the rejection does not merely depend on the existing semicolon check)
and for -delete.
@DavidLiedle
DavidLiedle merged commit 8d4e533 into devrelopers:main Sep 18, 2026
@DavidLiedle

Copy link
Copy Markdown
Contributor

Thanks for this, and for the careful write-up. You're right: find ** is in the default allowlist, so -exec … + was a zero-config bypass, and single-token entries are the right call given how the denylist matcher works. Merged. I'm following up with a few related hardening changes in the same area.

DavidLiedle added a commit that referenced this pull request Sep 18, 2026
Extends the hard denylist beyond find's -exec family (#1):

- find: -fprint, -fprint0, -fprintf, -fls write arbitrary files
  anywhere on disk; cwd containment only covers the working directory.
- rg --pre CMD runs CMD for every searched file.
- git diff/log/show --output=PATH writes to PATH.
- tree -o / --output writes to PATH (including bundled -ao).

Program-specific flags are matched against the basename of the first
token so they don't collide with unrelated uses (grep -o, rg --pretty).

Also applies rustfmt to the tests added in #1 so `cargo fmt --check`
passes on main again.
DavidLiedle added a commit that referenced this pull request Sep 18, 2026
#2)

Extends the hard denylist beyond find's -exec family (#1):

- find: -fprint, -fprint0, -fprintf, -fls write arbitrary files
  anywhere on disk; cwd containment only covers the working directory.
- rg --pre CMD runs CMD for every searched file.
- git diff/log/show --output=PATH writes to PATH.
- tree -o / --output writes to PATH (including bundled -ao).

Program-specific flags are matched against the basename of the first
token so they don't collide with unrelated uses (grep -o, rg --pretty).

Also applies rustfmt to the tests added in #1 so `cargo fmt --check`
passes on main again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants