T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/technical-audit.sh:14
- Finding
- Arbitrary Python Code Execution Through URL Interpolation<![CDATA[ ## Vulnerability Details **File Location**: `scripts/technical-audit.sh:14-19` **Vulnerability Type**: User-controlled input embedded in executable Python source **Risk Level**: Critical ### Vulnerable Code ```bash python3 -c " import requests, json, sys, time from urllib.parse import urlparse from bs4 import BeautifulSoup url = '$URL' deep = '$DEEP' ``` The same unsafe source-code interpolation pattern also appears in: - `scripts/geo-audit.sh:11-16` - `scripts/audit-page.sh:17` - `scripts/audit-geo.sh:9` - `scripts/audit-technical.sh:9` - `scripts/analyze-competitor.sh:29-41` - `scripts/track-keywords.sh:72-83` - `scripts/generate-report.sh:28-35` ### Technical Analysis The shell argument stored in `URL` is inserted directly into a Python program passed to `python3 -c`. Shell quoting does not make this safe because the substitution occurs before Python parses the generated source. An input containing a single quote can terminate the intended Python string. The attacker can then append arbitrary Python statements. Those statements can invoke operating-system commands, read environment variables, inspect local files, alter audit results, or make additional network requests. Unquoted heredocs in the other affected scripts similarly substitute values such as `KEYWORD`, `COMPETITORS`, `SITE`, and `TYPE` into executable Python source. ### Attack Path 1. An attacker persuades the Agent or user to audit a crafted URL, site, keyword, competitor value, or report type. 2. The shell stores the value without validating it as a safe URL or identifier. 3. The value is interpolated into Python source code. 4. A quote in the value closes the intended string literal. 5. Injected Python statements execute with the permissions and environment of the Skill process. 6. The injected code can access workspace files, environment-based API keys, and any other resources available to the Agent account. ### Impact Assessment Successful exploitation provides arbitra ...[truncated 554 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Never construct Python source code from shell arguments. - Pass the URL as a positional argument: ```bash python3 "$SCRIPT_DIR/technical_audit.py" --url "$URL" ``` - Parse it in Python with `argparse`: ```python parser.add_argument("--url", required=True) args = parser.parse_args() url = args.url ``` - If a heredoc is unavoidable, use a single-quoted delimiter and retrieve values from the environment: ```bash export AUDIT_URL="$URL" python3 <<'PYEOF' import os url = os.environ["AUDIT_URL"] PYEOF ``` - Apply the same correction to every affected URL, keyword, competitor, site, type, and output-path interpolation. - Validate URLs, hostnames, report types, and numeric arguments independently after safely transporting them into Python. - Add regression tests containing quotes, backslashes, newlines, command substitutions, and traversal sequences. ]]>
