T09 · Insecure Skill Coding Practices
- Location
scripts/train_loop.py:14- Finding
JSON Command Mode Permits Shell-Interpreter Injection
- Content
View full analysis
", ">>", "<"]): raise ValueError("Shell operators are not allowed in command string.") args = shlex.split(command, posix=(os.name != "nt")) dangerous_tokens = {"&&", "||", ";", "|", ">", ">>", "<", "2>", "&"} if any(token in dangerous_tokens for token in args): raise ValueError("Shell operators are not allowed. Provide a direct executable command.") return args def run_command(command): """ Runs the command safely with shell disabled and captures output. """ args = parse_safe_command(command) print(f"Executing (safe argv): {args}") try: result = subprocess.run(args, shell=False, check=True, capture_output=True, text=True) return result.stdout, result.stderr except subprocess.CalledProcessError as e: print(f"Command failed with error: {e}") return e.stdout, e.stderr ``` ### Technical Analysis The non-JSON command branch rejects shell operators appearing anywhere in the command string. The JSON branch, however, only rejects an operator when an entire argument exactly equals an entry in `dangerous_tokens`. Consequently, a complete shell expres ...[truncated 2006 chars]- Remediation
View remediation
