Skip to content

fix: harden CommandValidator to cover missed absolute paths + sensitive-file exfil (issue #17) - #18

Merged
chouzz merged 1 commit into
chouzz:mainfrom
sudo-ai-git:fix/harden-validation
Aug 31, 2026
Merged

chouzz merged 1 commit into
chouzz:mainfrom
sudo-ai-git:fix/harden-validation

Conversation

@sudo-ai-git

Copy link
Copy Markdown
Contributor

Fix: harden CommandValidator to cover missed absolute paths + sensitive-file exfil (issue #17)

Addresses issue #17 (responsible disclosure: the blacklist blocks only ~11 exact root paths, so rm -rf /home, /tmp, /mnt, individual files, and cat/cp/tar exfil of /etc/shadow all passed deterministically).

Changes (src/remoteshell_mcp/command_validator.py)

  • Block rm -rf on absolute paths under /home, /tmp, /mnt, /data, /opt, /srv, /media and on arbitrary absolute paths (individual files/dirs).
  • Block cat/cp/mv/tar/dd/scp/nc/rsync on sensitive system/private files (/etc/shadow, /etc/passwd, /etc/sudoers, /root/.ssh, ~/.ssh).

Verified (with the repo's real CommandValidator.validate())

  • Now blocked: rm -rf /home, /home/*, /etc/passwd, /tmp, /mnt/data, cat /etc/shadow, cp /etc/shadow /home/leak, tar czf /home/leak.tgz /etc/shadow.
  • Still pass (relative/benign): ls /home, cat ~/notes.txt, grep foo /var/log/syslog, cd /tmp && ls, rm -rf ./test, echo hello, git status.

Honest scope note

A blacklist is still not a full security boundary on a remote-shell tool — an allowlist of safe commands + shell-metachar rejection (and removing the REMOTESHELL_DISABLE_VALIDATION kill-switch) is the stronger, recommended hardening. This PR is a material tightening that closes the demonstrated bypasses while preserving legitimate relative-path usage.

…ve-file exfil (issue chouzz#17)

The blacklist blocked only ~11 exact root paths; 'rm -rf /home', '/tmp', '/mnt',
individual files (e.g. /etc/passwd), and cat/cp/tar exfil of /etc/shadow all passed
deterministically. Added:
- block rm -rf on absolute paths under /home /tmp /mnt /data /opt /srv /media and
  on arbitrary absolute paths (individual files/dirs)
- block cat/cp/mv/tar/dd/scp/nc/rsync on sensitive system/private files
  (/etc/shadow, /etc/passwd, /etc/sudoers, /root/.ssh, ~/.ssh)

Verified: all previously-passing bypass payloads now BLOCKED; legit relative-path
and benign commands (ls, cat ~/notes, grep, cd && ls, rm -rf ./test, echo, git)
still pass. Note: a blacklist is still not a full security boundary on a remote
shell tool — an allowlist of safe commands remains the stronger hardening.
@chouzz

chouzz commented Aug 31, 2026

Copy link
Copy Markdown
Owner

Hi,thanks. That's also what I want to do.

@chouzz
chouzz merged commit e01fb9b into chouzz:main Aug 31, 2026
@sudo-ai-git

Copy link
Copy Markdown
Contributor Author

Hi — great, happy to help land it. A couple of notes for the full hardening (beyond the path-list tightening in the PR): the same gap can reappear through file exfil of sensitive credentials, command chaining (;/&&/|), and the REMOTESHELL_DISABLE_VALIDATION kill-switch. The strongest form is a small allowlist of the commands you actually want to expose (with a deny-by-default fallthrough) rather than a growing blacklist. I can turn that into a follow-up PR if useful — and I audit remote-exec MCP servers like this as a service (verified findings, SARIF, evidence gates) if you ever want a deeper pass on the SSH transport + validation. Either way, happy to help the current fix merge.

— SudoShellz (sudo-ai-git)

chouzz added a commit that referenced this pull request Sep 14, 2026
…wildcard wipes (#21)

#18's fallback 'Remove arbitrary absolute path' rule blocked EVERY
absolute-path rm -rf, including /root/myapp/build or /tmp/build —
this tool's normal daily use. Worse, it trained callers to bypass the
validator entirely via 'cd /root && rm -rf subdir'.

Rework the hardening rules:
- block rm -rf targeting any TOP-LEVEL absolute path (any argument,
  optional trailing slash): rm -rf /, /home, /etc/, multi-arg variants
- block wildcard wipes (rm -rf /home/*, /*) and critical system files
  (/etc/shadow, /etc/passwd, /etc/sudoers, /etc/fstab, /etc/group,
  /etc/gshadow, /boot/*)
- ALLOW nested paths (depth >= 2): rm -rf /root/otherdirectory,
  /tmp/build, /home/user/project, /etc/nginx

Also fix the keyword-layer 'rm -rf /root\b' pattern whose word boundary
between 't' and '/' made it match /root/child too.

All issue #17 payloads remain blocked (verified in tests).
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