Skip to content

Skip /dev/null redirects from terminal auto-allow command extraction#49503

Merged
rtfeldman merged 3 commits intomainfrom
AI-41/terminal-regex-false-negatives
Feb 18, 2026
Merged

Skip /dev/null redirects from terminal auto-allow command extraction#49503
rtfeldman merged 3 commits intomainfrom
AI-41/terminal-regex-false-negatives

Conversation

@rtfeldman
Copy link
Contributor

@rtfeldman rtfeldman commented Feb 18, 2026

Redirects to /dev/null (e.g. 2>/dev/null, &>/dev/null) are known-safe I/O routing, not commands. Previously, extract_commands emitted normalized redirect strings like "2> /dev/null" as separate entries in the command list checked against auto-allow regexes. Since check_commands requires all extracted entries to match an allow pattern, the unmatched redirect caused false-negatives — e.g. git log --oneline -20 2>/dev/null || echo ... would not be auto-allowed despite matching ^git and ^echo patterns.

Rather than removing all redirects from extraction (which would hide dangerous redirects like > /etc/passwd from deny/confirm pattern checking), this fix surgically skips only /dev/null targets during redirect normalization. Redirects to real files are still emitted and still require a matching pattern for auto-allow, preserving the defense-in-depth property.

Closes AI-41

Release Notes:

  • Fixed terminal auto-allow patterns incorrectly prompting for confirmation on commands containing /dev/null redirects (e.g. 2>/dev/null).

File redirects (e.g. `2>/dev/null`, `> output.txt`) are I/O routing,
not commands, and should not be checked against auto-allow regexes.

Previously, `extract_commands` emitted normalized redirect strings like
`"2> /dev/null"` as separate commands. Since `check_commands` requires
all extracted commands to match an allow pattern, the unmatched redirect
caused false-negatives — e.g. `git log --oneline -20 2>/dev/null || echo ...`
would not be auto-allowed despite matching `^git` and `^echo` patterns.

Nested commands within redirect targets (e.g. process substitutions like
`> $(mktemp)`) are still extracted via the existing second pass in
`extract_commands_from_io_redirect`.
Verifies that a piped command like `echo "y\ny" | git add -p file`
is auto-allowed when both sides match their respective allow patterns.
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 18, 2026
@zed-community-bot zed-community-bot bot added the staff Pull requests authored by a current member of Zed staff label Feb 18, 2026
Redirects to /dev/null (e.g. 2>/dev/null, &>/dev/null) are known-safe
I/O routing, not commands. Previously they were emitted as separate
entries in the extracted command list, causing auto-allow to fail because
check_commands requires all entries to match a pattern.

Instead of removing all redirects from extraction (which would hide
dangerous redirects like > /etc/passwd from deny patterns), this
surgically skips only /dev/null targets during normalization.
@rtfeldman rtfeldman changed the title Exclude file redirects from terminal auto-allow command extraction Skip /dev/null redirects from terminal auto-allow command extraction Feb 18, 2026
@rtfeldman rtfeldman marked this pull request as ready for review February 18, 2026 18:00
@rtfeldman rtfeldman requested a review from a team as a code owner February 18, 2026 18:00
@rtfeldman rtfeldman merged commit bf1bb52 into main Feb 18, 2026
28 checks passed
@rtfeldman rtfeldman deleted the AI-41/terminal-regex-false-negatives branch February 18, 2026 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant