feat: Implement command execution handler for server#148
Merged
Conversation
Implement the exec_request handler for bssh-server, enabling clients to execute remote commands via SSH. Features include: - CommandExecutor with configurable shell and timeout - Stdout/stderr streaming to SSH channel - Command allow/block list validation for security - Exit code propagation to client - Environment variable configuration (HOME, USER, SHELL, PATH) - Working directory configuration - Proper channel lifecycle (success, eof, close) Closes #128
This commit addresses all CRITICAL and HIGH severity security vulnerabilities identified in PR #148 code review. CRITICAL Issues Fixed: 1. Command Injection via Blocklist Bypass - Implement normalized validation (lowercase, whitespace collapse) - Add regex-based pattern detection for variable expansion - Detect all shell metacharacters (;, &&, ||, |, $(), etc.) - Case-insensitive and normalized blocklist matching 2. Allowlist Validation Bypass - Detect and reject command chaining in allowlist mode - Change to exact match only (no prefix matching) - Prevent "ls; rm -rf /" style bypasses 3. Process Privilege Control - Add process group creation for better isolation - Document OS-level privilege control requirements - Use kill_on_drop for automatic cleanup HIGH Issues Fixed: 4. Zombie Process Risk on Timeout - Create new process group with process_group(0) - Kill entire process group on timeout using kill(-pid, SIGKILL) - Implement fallback to immediate child kill 5. Resource Limits - Add documentation for OS-level resource limits - Recommend systemd service limits and ulimit configuration 6. Environment Variable Security - Block dangerous environment variables (LD_PRELOAD, LD_LIBRARY_PATH, etc.) - Add runtime filtering with warning logs - Prevent library injection and environment-based attacks Implementation Details: - Enhanced validation with multiple defense layers - Comprehensive test suite with 17 passing tests - Updated default blocklist to block command categories - Added dangerous environment variable blocklist - Process group management for Unix systems - Updated dependencies: nix (process, signal features), libc Breaking Changes: - Default blocklist now blocks command names instead of full patterns - Command chaining strictly blocked when allowlist is configured - Case-insensitive command blocking (RM, Rm blocked along with rm) - Dangerous environment variables are now filtered Testing: - All 17 exec module tests pass - Comprehensive injection prevention tests added - Blocklist normalization tests - Allowlist bypass prevention tests - Environment variable filtering tests
Apply cargo fmt formatting and add #[allow(dead_code)] for test helper
Member
Author
PR Finalization ReportProject Structure Discovered
ChecklistTests
Documentation
Code Quality
Changes Made
Notes
|
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.
Summary
Changes
New Files
src/server/exec.rs- CommandExecutor implementationModified Files
src/server/mod.rs- Export exec modulesrc/server/config.rs- Add ExecConfig optionssrc/server/handler.rs- Implement exec_request handlerImplementation Details
CommandExecutor Features
Security Features
Test plan
Closes #128