Files
python-sdk/pkg/hanzo-mcp/SECURITY_PATCH.md
T
zeekay 1bbf1d51f6 feat: Add universal auto-timeout and backgrounding for MCP tools
- Implement MCPToolTimeoutManager with configurable timeouts
- Add @auto_timeout decorator for all MCP tools
- Apply auto-timeout to search, find, and ast tools
- Default 2-minute timeout, configurable via HANZO_MCP_TOOL_TIMEOUT
- Background operations continue with full log files
- Process management integration for monitoring and termination
- Solves MCP error -32001 (Request timed out) issues

Version bump: 0.8.15 → 0.8.16
2025-09-25 01:17:34 -05:00

3.5 KiB

Security Patch for Hanzo MCP v0.8.13

Critical Security Vulnerabilities Found

1. Command Injection (CRITICAL) 🚨

Location: hanzo_mcp/tools/shell/command_executor.py line 114 Issue: Insufficient shell escaping using basic string replacement Risk: Remote code execution

Current Code:

escaped_command = command.replace('"', '\\"')

Fixed Code:

import shlex
escaped_command = shlex.quote(command)

2. Path Traversal (HIGH) ⚠️

Location: hanzo_mcp/tools/common/permissions.py Issue: No validation for symlinks and ../ traversal Risk: Unauthorized file access

Add validation:

def validate_path(self, path: str) -> bool:
    """Validate path against traversal attacks."""
    resolved = Path(path).resolve()
    
    # Check for path traversal
    if ".." in str(path):
        return False
    
    # Check against allowed paths
    for allowed in self.allowed_paths:
        try:
            resolved.relative_to(allowed)
            return True
        except ValueError:
            continue
    
    return False

3. Missing Authentication (HIGH) ⚠️

Location: hanzo_mcp/server.py Issue: MCP server accepts any local connection without auth Risk: Unauthorized access to system

Add basic token auth:

import secrets
import os

class HanzoMCPServer:
    def __init__(self, ...):
        self.auth_token = os.environ.get('HANZO_MCP_TOKEN') or secrets.token_urlsafe(32)
        
    def verify_auth(self, request_token: str) -> bool:
        """Verify authentication token."""
        return secrets.compare_digest(request_token, self.auth_token)

4. Subprocess Timeout (MEDIUM)

Location: Multiple subprocess.run() calls Issue: Missing consistent timeout enforcement Risk: Resource exhaustion from hanging processes

Fix:

# Always use timeout
result = subprocess.run(
    command,
    timeout=self.command_timeout,  # Default 120s
    check=False,
    capture_output=True
)

Test Results Summary

  • Total Tests: 410 collected
  • Test Errors: 4 collection errors
  • Status: Tests not fully passing due to environment issues
  • Recommendation: Fix security issues first, then resolve test environment

Immediate Actions Required

  1. Apply command injection patch using shlex.quote()
  2. Add path validation to PermissionManager
  3. Implement token authentication for MCP server
  4. Add timeout to all subprocess calls
  5. Add audit logging for all operations
  6. Implement rate limiting to prevent abuse

Risk Assessment

Vulnerability Severity Exploitability Impact Priority
Command Injection CRITICAL High RCE P0
Path Traversal HIGH Medium File Access P1
No Authentication HIGH High Unauthorized Access P1
Missing Timeouts MEDIUM Low DoS P2

Deployment Recommendation

DO NOT DEPLOY TO PRODUCTION until:

  1. All CRITICAL and HIGH severity issues are patched
  2. Authentication is implemented
  3. Test suite is passing (currently has environment issues)
  4. Security audit is performed on patched version

Next Version Plan (v0.8.14)

Should include:

  • Security patches for all identified vulnerabilities
  • Authentication system
  • Audit logging
  • Rate limiting
  • Improved error handling
  • Complete test coverage

Generated by Code Review Agent Date: 2024-12-20 Version Reviewed: hanzo-mcp v0.8.13