T09 · Insecure Skill Coding Practices
- Location
scripts/stockfish_fen.py:118- Finding
UCI Protocol Command Injection Through Unvalidated FEN Input
- Content
View full analysis
int: engine = locate_engine(args.engine) if not engine: print(json.dumps({"ok": False, "error": "stockfish not found", "install": "Install stockfish or set STOCKFISH_PATH."}, indent=2)) return 3 commands = [ "uci", "isready", f"setoption name MultiPV value {args.multipv}", f"position fen {args.fen}", ] commands.append(f"go depth {args.depth}" if args.depth else f"go movetime {int(args.limit * 1000)}") ``` The resulting commands are sent directly to Stockfish at `scripts/stockfish_fen.py:36-45`: ```python def run_stockfish(engine: str, commands: list[str], timeout: float = 20.0) -> list[str]: proc = subprocess.Popen( [engine], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, encoding="utf-8", errors="replace", bufsize=1, ) assert proc.stdin is not None and proc.stdout is not None out: list[str] = [] for command in commands: proc.stdin.write(command + "\n") proc.stdin.flush() ``` ### Technical Analysis The value of `args.fen` is interpolated directly into a line of the UCI protocol without parsing the FEN or rejecting carriage returns, line feeds, and other control characters. Because each newline delimits a command in UCI, a malicious FEN argument containing an embedded newline can append additional commands to Stockfish. This is not shell-command injection because `subprocess.Popen` uses an argument list and does not invoke a shell. The injection is confined to commands recognized by the selected chess engine. Nevertheless, relevant UCI commands can alter engine options, consume resources, terminate the process, or desy ...[truncated 1574 chars]- Remediation
View remediation
