Repository navigation
fix: stop blocking harmless /dev/null redirections in CommandValidator - #19
Merged
Merged
Conversation
The pattern '>/dev/' blocked any redirect to any /dev/ file, including /dev/null, /dev/stdout, /dev/stderr and /dev/full — breaking the standard '2>/dev/null' stderr-discard idiom. Replace with a whitelist of real storage device prefixes (sd, hd, vd, xvd, nvme, mmcblk, loop, mapper, sr, fd) so only overwrites of actual block devices are rejected. Future harmless /dev/* character devices are allowed by default.
This was referenced Sep 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
CommandValidatorrule(r'>\s*/dev/', 'Redirect to device file')rejects any command containing a>redirect to any/dev/...path, including the extremely common, harmless idiom:some_cmd 2>/dev/nullThe rule's intent is to block catastrophic overwrites of real storage devices (e.g. writing raw output to a disk), but its granularity is too coarse: it doesn't distinguish dangerous block devices from harmless character devices like
/dev/null(a data sink by definition — writing to it can never be destructive).Fix
Replace the blanket rule with a whitelist of real storage device prefixes, instead of a denylist-style
(?!null)lookahead — this also auto-allows future harmless/dev/*character devices:Covered prefixes:
sd(SATA/SCSI),hd(IDE),vd(virtio),xvd(Xen),nvme(incl.nvme0n1),mmcblk(SD/eMMC),loop,mapper(LVM/dm-crypt),sr(CD/DVD),fd(floppy).Still blocked:
echo x > /dev/sdaecho x >/dev/nvme0n1echo x > /dev/mapper/vg-rootNow allowed:
echo hello 2>/dev/nullcmd > /dev/null 2>&1cat /etc/hostname > /dev/fullecho x 1>/dev/stdout 2>/dev/stderrNote (not changed in this PR)
The validator is still regex-over-string, not shell-syntax-aware, so any text content that happens to contain a redirect-to-block-device pattern inside a quoted string would still false-positive — a known structural limitation of this class of validator, out of scope here.
Tests
Added 7 test cases (3 blocked block-device overwrites + 4 allowed harmless redirections). Full suite: 12 passed.