T09 · Insecure Skill Coding Practices
- Location
scripts/elpa_orchestrator.py:56- Finding
Shell Command Injection Through Configuration-Derived Commands and Placeholder Values
- Content
View full analysis
str: try: return template.format(**context) except KeyError as exc: missing = str(exc).strip("'") raise ValueError(f"missing placeholder '{missing}' in context for command: {template}") from exc ``` ```python context = _build_context(cfg, run_dir=run_dir, model_dir=model_dir, model_name=name) command = _render_command(cmd_template, context) ``` ```python completed = subprocess.run( item["train_cmd"], shell=True, cwd=item["model_dir"], env=env, stdout=out_f, stderr=err_f, check=False, ) ``` ### Technical Analysis The orchestrator reads `train_cmd` templates and placeholder values from a JSON configuration, combines them using Python string formatting, and submits the resulting string to `subprocess.run()` with `shell=True`. Because the generated command is interpreted by a command shell, shell metacharacters in either the template or substituted values retain their special meaning. A value intended to represent only a dataset path, project path, interpreter, or other argument can therefore introduce additional commands through characters such as `;`, `|`, command substitution, or redirection. For example, a configuration-derived dataset value conceptually equivalent to: ```text /path/to/data.csv; attacker-command ``` would be inserted directly into the command string. When execution is enabled, the shell interprets the text after the semicolon as another command. The documented design intentionally permits users to specify training commands. Nevertheless, the implementation does not distinguish executable command structure from data-only placeholder values. Consequently, configurations ob ...[truncated 1659 chars]- Remediation
View remediation
