T09 · Insecure Skill Coding Practices
- Location
scripts/full_pipeline.py:264- Finding
Shell Command Injection Through Attacker-Controlled Document Names or Output Suffixes
- Content
View full analysis
/dev/null' result = subprocess.run(cmd, shell=True, capture_output=True, text=True) ``` The affected filename is constructed from command-line-controlled values: ```python parser.add_argument('input', help='Input file (.doc or .docx)') parser.add_argument('--suffix', default='-修订痕迹版', help='Output filename suffix') ``` ```python stem = input_path.stem revised_path = output_dir / f"{stem}{args.suffix}.docx" clean_path = output_dir / f"{stem}{args.suffix}-清洁版.docx" if not generate_clean(revised_path, clean_path): log("Clean document generation failed; retaining revised document", "WARN") ``` ### Technical Analysis The input document stem and the optional `--suffix` value are incorporated into `revised_path.name`. That filename is copied into a temporary directory and interpolated directly into a command string passed to `subprocess.run()` with `shell=True`. Wrapping the path in double quotes does not neutralize shell metacharacters. POSIX shells still evaluate command substitution, parameter expansion, and certain other constructs inside double-quoted strings. Therefore, a filename or suffix containing shell substitution syntax can cause the shell to execute an additional command. The vulnerable fallback is reached when the primary clean-document implementation raises an exception. A malformed o ...[truncated 2042 chars]- Remediation
View remediation
