Spaces:
Paused
Paused
Update Modules/Shell_Command.py
Browse files95 unmodified lines9697989910010195 unmodified lines_log_call_end("Shell_Command", _truncate_for_log(result))return result# Capture shell used for transparency_, shell_name = _detect_shell()stdout, stderr, code = _run_command(command, cwd=abs_cwd, timeout=timeout)95 unmodified lines9697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415595 unmodified lines_log_call_end("Shell_Command", _truncate_for_log(result))return result# Heuristic check for absolute paths in arguments if sandboxing is strictly enforced# We look for typical absolute path patterns: "/..." or "C:\..."# This is not perfect (e.g., inside strings) but helps enforce "Impossible" rule.from .File_System import ALLOW_ABSimport reif not ALLOW_ABS:# Regex for Unix-style absolute path (start with /)# or Windows-style absolute path (start with drive letter)# We look for these patterns preceded by space or start of string# to avoid matching arguments like --flag=/value (though those might be paths too!)# Actually, matching ANY absolute path substring is safer for "Impossible".# Patterns:# Unix: / followed by non-space# Win: X:\ followed by non-space# Simple heuristic: if command contains potential absolute pathunix_abs = r"(?:\s|^)/[a-zA-Z0-9_.]"win_abs = r"(?:\s|^)[a-zA-Z]:\\"if re.search(unix_abs, command) or re.search(win_abs, command):# We allow a few exceptions if needed, but for "Impossible" we block.# Note: This might block flags like /C, but we run powershell/cmd separately.# Wait, Windows flags start with /. 'dir /s'. This heuristic is dangerous for Windows flags.# We should refine it.pass# Refined check:# On Windows, flags start with /, so checking for / is bad.# But paths in Windows usually use \ or /.# Let's focus on Unix roots and Windows Drive roots.has_abs_path = Falseif platform.system().lower() == "windows":# Look for Drive:\ - anchored to start of string, space, or quote to avoid matching URLs like https://if re.search(r"(?:\s|^|['\"])[a-zA-Z]:[\\/]", command):has_abs_path = True# On Windows with PowerShell, /path is valid too, but confusing with flags.# We'll trust that Drive:\ is the main vector to save OUTSIDE tool root (which is likely C: or P:).# If tool root is P:/Code..., writing to C:/... requires Drive arg.else:# Unix: Look for / at start of token, but exclude common flags?# Actually, just looking for " /" or start "/" is decent.# But flags like /dev/null are common.# Maybe we just warn or block known dangerous patterns?# User said "Make it impossible". a broad block is better than a leak.if re.search(r"(?:\s|^)/", command):# This blocks flags like /bin/bash or paths.has_abs_path = Trueif has_abs_path:result = "Error: Absolute paths are not allowed in commands to ensure sandbox safety. Use relative paths."_log_call_end("Shell_Command", _truncate_for_log(result))return result# Capture shell used for transparency_, shell_name = _detect_shell()stdout, stderr, code = _run_command(command, cwd=abs_cwd, timeout=timeout)
Modules/Shell_Command.py+54