T09 · Insecure Skill Coding Practices
- Location
scripts/download_articles.py:72- Finding
Shell Command Injection Through Attacker-Controlled WORKSPACE Path
- Content
View full analysis
{pdf_path}") cmd = f'google-chrome --headless --disable-gpu --print-to-pdf={pdf_path} --print-to-pdf-no-header --paper-size=A4 {html_path}' os.system(cmd) ``` The paths passed to `convert_to_pdf` are derived from `WORKSPACE`: ```python html_path = os.path.join(WORKSPACE, f"young-post-spark-{date_str}.html") pdf_path = os.path.join(WORKSPACE, f"young-post-spark-{date_str}.pdf") convert_to_pdf(html_path, pdf_path) ``` ### Technical Analysis The `WORKSPACE` environment variable is accepted without validation and incorporated into `html_path` and `pdf_path`. These values are then interpolated directly into a shell command executed by `os.system`. Because `os.system` invokes a command shell, shell metacharacters contained in the workspace path—such as semicolons, command substitutions, redirection operators, or comment characters—are interpreted as shell syntax rather than as literal path characters. Neither path is shell-escaped or passed as a distinct process argument. The earlier HTML file write does not reliably prevent exploitation. An attacker who can set the environment and create directories may create a literal directory whose name contains shell metacharacters, allowing the file write to succeed before those same characters are interpreted by the shell during PDF conversion. ### Attack Path 1. The attacker gains control over the `WORKSPACE` environment variable used to launch the skill. 2. The attacker creates a writable directory with a specially crafted name containing shell sy ...[truncated 1379 chars]- Remediation
View remediation
