[PR #2] [MERGED] Fix exit codes, shell escaping, validation, and logging #3

Closed
opened 2026-03-02 03:44:34 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/devnullvoid/mcp-ssh-session/pull/2
Author: @google-labs-jules[bot]
Created: 12/5/2025
Status: Merged
Merged: 12/5/2025
Merged by: @devnullvoid

Base: mainHead: ssh-session-improvements


📝 Commits (1)

  • d15ef5d Fix SSH session issues and improve logging

📊 Changes

3 files changed (+122 additions, -15 deletions)

View changed files

📝 mcp_ssh_session/command_executor.py (+87 -5)
📝 mcp_ssh_session/file_manager.py (+12 -6)
📝 mcp_ssh_session/session_manager.py (+23 -4)

📄 Description

This PR addresses several critical issues and improvements identified in docs/CODE_REVIEW.md:

  1. Exit Code Retrieval (#5): Implemented logic to retrieve the actual exit code (using echo $? or equivalent) for commands that complete during background monitoring after a timeout. This ensures exit_code is accurate instead of defaulting to 0 or None.
  2. Shell Escaping Fix (#15): Replaced manual character escaping in write_file (sudo mode) with base64 encoding/decoding. This prevents vulnerabilities and bugs related to special characters (newlines, quotes, etc.) in file content.
  3. Enable Mode Validation (#9): Added validation in _execute_enable_mode_command_internal to check if the session is actually in enable mode (prompt ends with #) before executing commands. It attempts to re-enter enable mode if the validation fails.
  4. Logging Improvements (#14): Implemented rate limiting for debug logs inside tight recv loops in command_executor.py to prevent log flooding during long operations or idle states.

Verified with targeted reproduction tests and existing regression tests.


PR created automatically by Jules for task 11506711411728051988 started by @devnullvoid


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/devnullvoid/mcp-ssh-session/pull/2 **Author:** [@google-labs-jules[bot]](https://github.com/apps/google-labs-jules) **Created:** 12/5/2025 **Status:** ✅ Merged **Merged:** 12/5/2025 **Merged by:** [@devnullvoid](https://github.com/devnullvoid) **Base:** `main` ← **Head:** `ssh-session-improvements` --- ### 📝 Commits (1) - [`d15ef5d`](https://github.com/devnullvoid/mcp-ssh-session/commit/d15ef5d701b545fc1d1bd348ba1e3e7386ebc7d9) Fix SSH session issues and improve logging ### 📊 Changes **3 files changed** (+122 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `mcp_ssh_session/command_executor.py` (+87 -5) 📝 `mcp_ssh_session/file_manager.py` (+12 -6) 📝 `mcp_ssh_session/session_manager.py` (+23 -4) </details> ### 📄 Description This PR addresses several critical issues and improvements identified in `docs/CODE_REVIEW.md`: 1. **Exit Code Retrieval (#5)**: Implemented logic to retrieve the actual exit code (using `echo $?` or equivalent) for commands that complete during background monitoring after a timeout. This ensures `exit_code` is accurate instead of defaulting to 0 or None. 2. **Shell Escaping Fix (#15)**: Replaced manual character escaping in `write_file` (sudo mode) with `base64` encoding/decoding. This prevents vulnerabilities and bugs related to special characters (newlines, quotes, etc.) in file content. 3. **Enable Mode Validation (#9)**: Added validation in `_execute_enable_mode_command_internal` to check if the session is actually in enable mode (prompt ends with `#`) before executing commands. It attempts to re-enter enable mode if the validation fails. 4. **Logging Improvements (#14)**: Implemented rate limiting for debug logs inside tight `recv` loops in `command_executor.py` to prevent log flooding during long operations or idle states. Verified with targeted reproduction tests and existing regression tests. --- *PR created automatically by Jules for task [11506711411728051988](https://jules.google.com/task/11506711411728051988) started by @devnullvoid* --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-02 03:44:34 +03:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/mcp-ssh-session#3
No description provided.