Skip to content

Guard find -fprint/-fprintf/-fls (they write to a file) - #151

Merged
ldayton merged 1 commit into
mainfrom
lily/150-find-fprint-guard
Jun 8, 2026
Merged

Guard find -fprint/-fprintf/-fls (they write to a file)#151
ldayton merged 1 commit into
mainfrom
lily/150-find-fprint-guard

Conversation

@ldayton

@ldayton ldayton commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Fixes #150.

find's -fprint, -fprint0, -fprintf, and -fls write find's output to a file, truncating it — the same destructive effect as a > file redirect, which Dippy already guards. They'd been grouped with -print/-printf/-ls as safe "print actions", but those write to stdout; the f prefix means file.

This was an inconsistency: Dippy asks on one syntax and silently allows the other for the identical effect.

Command Before After
find . > /etc/hosts ask ask
find . -fprint /etc/hosts allow ask
find . -print (stdout) allow allow

Changes

  • find.py: route -fprint/-fprint0/-fprintf/-fls to ask, alongside -delete.
  • test_find.py: move those four out of the "Print actions (safe)" cases (they were asserted approved) into the file-writing group, expecting ask.

Surfaced while investigating #130 (the -delete case, which was already guarded).

Full suite: 11001 passing.

These actions write find's output to a file, truncating it — the same
destructive effect as a `> file` redirect, which Dippy already asks on.
They were grouped with -print/-printf/-ls (stdout, safe) by name, but the
`f` prefix means 'file'. Route them to ask alongside -delete.

Fixes #150.
@ldayton
ldayton merged commit 3e8a5fd into main Jun 8, 2026
1 check passed
ldayton added a commit that referenced this pull request Jun 8, 2026
find's -fprint/-fprint0/-fprintf/-fls write find's output to the file that
follows them, the same effect as a `> file` redirect. #151 routed them to a
blanket ask; this surfaces the file argument as a redirect_target (the
sort -o pattern) so the usual redirect rules apply: deny-redirect hard-blocks
the path, allow-redirect pre-approves it, and an unmatched write defaults to
ask — identical to the equivalent `> file` redirect.

-delete/-exec/-ok handling is unchanged. A code comment notes the one known
limitation: when a write is combined with -delete/-exec, the earlier branch
returns first, so the target isn't separately gated (degrades to ask, never
weaker).

Adds TestFindFileWriteRedirectRules covering default->ask, deny-redirect->deny,
allow-redirect->approve, and parity with the `>` redirect.
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.

find -fprint/-fls/-fprintf write files but aren't guarded

1 participant