T09 · Insecure Skill Coding Practices
- Location
scripts/wow_daily_news.py:18- Finding
Remote Command Injection Through an Untrusted Article URL
- Content
View full analysis
tuple[bool, str]: try: result = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=timeout) return result.returncode == 0, result.stdout + result.stderr except Exception as e: return False, str(e) def close_browser(): run_cmd('agent-browser close', 10) def open_page(url: str) -> bool: run_cmd('agent-browser close', 10) time.sleep(1) success, _ = run_cmd(f'agent-browser open "{url}" --timeout 45000', 60) return success ``` The URL supplied to `open_page()` is derived from remotely retrieved EXWIND page content: ```python if '/url: /post/' in line and current.get('title'): match = re.search(r'/url: (/\S+)', line) if match: current['url'] = f"https://exwind.net{match.group(1)}" ``` ### Technical Analysis `run_cmd()` invokes `subprocess.run()` with `shell=True`. The `open_page()` function embeds its `url` argument directly into a shell command string. The URL is surrounded by double quotes, but quoting alone does not prevent command injection. An attacker-controlled value can contain a double quote followed by shell syntax, terminate the intended argument, and introduce another command. The parser accepts any non-whitespace characters after `/url:`, without validating the resulting URL's hostname, path, characters, or canonical form. Because article URLs are parsed from remote webpage content and later passed to `get_exwind_article_content()`, which invokes `open_page()`, compromised or attacker-influenced source content can reach the operating-system shell. ### Attack Path 1. An attacker compromises EXWIND content, its delivery path, or another mechanism capable of influencing the browser snapshot. 2. The attacker supplie ...[truncated 1245 chars]- Remediation
View remediation
tuple[bool, str]: try: result = subprocess.run( args, shell=False, capture_output=True, text=True, timeout=timeout, check=False, ) return result.returncode == 0, result.stdout + result.stderr except Exception as exc: return False, str(exc) def close_browser(): run_cmd(["agent-browser", "close"], 10) def open_page(url: str) -> bool: close_browser() time.sleep(1) success, _ = run_cmd( ["agent-browser", "open", url, "--timeout", "45000"], 60, ) return success ``` 2. Validate every remotely derived URL before use: ```python from urllib.parse import urlparse def validate_exwind_url(url: str) -> str: parsed = urlparse(url) if parsed.scheme != "https": raise ValueError("Unexpected URL scheme") if parsed.hostname != "exwind.net": raise ValueError("Unexpected URL host") if not parsed.path.startswith("/post/"): raise ValueError("Unexpected URL path") if parsed.username or parsed.password or parsed.port: raise ValueError("Unexpected URL authority") return url ``` 3. Reject control characters and malformed URLs rather than attempting to sanitize shell syntax. 4. Apply URL validation at the trust boundary, immediately after parsing remote content. 5. Run the Skill under a least-privileged account with restricted filesystem and network access as defense in depth. 6. Add regression tests containing quotes, command substitutions, semicolons, newlines, and other shell metacharacters. ]]>
