T09 · Insecure Skill Coding Practices
Error
- Location
- SKILL.md:12
- Finding
- Shell Command Injection Through User-Controlled Command Arguments<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md`, lines 12-25 **Vulnerability Type**: OS command injection caused by unsafe shell command construction **Risk Level**: High ### Vulnerable Code ```markdown - Trích xuất mã cổ phiếu (`ticker`): ví dụ `FPT`, `VCB`, `HPG`. - Sử dụng tool `exec` gọi lệnh: ```bash python3 /home/hoang/.openclaw/workspace/vn-stock-scanner/scripts/scanner.py ticker --ticker <mã_cổ_phiếu> ``` - Dùng thông tin trả về (P/E, P/B, EPS, Tỷ suất cổ tức...) để trả lời user và đưa ra nhận định ngắn gọn. ## 2. Quét tin tức và tin đồn (News & Rumor Scanner) Khi user hỏi "Có tin tức chứng khoán gì hot không?", "Tìm tin đồn", "Chủ tịch đăng ký mua bán": - Nhận diện từ khóa user quan tâm (`keywords`). Nếu user muốn tin chung chung thì bỏ trống. Nếu user muốn tin về mua/bán nội bộ, thì truyền `keywords="mua,bán,chủ tịch,đăng ký"`. - Sử dụng tool `exec` gọi lệnh: ```bash python3 /home/hoang/.openclaw/workspace/vn-stock-scanner/scripts/scanner.py news --keywords "<từ_khóa>" ``` ``` ### Technical Analysis The Skill directs the Agent to extract ticker symbols or keywords from user input and interpolate them into shell command templates executed through `exec`. The ticker placeholder is entirely unquoted. Consequently, shell operators, command separators, substitutions, redirections, and additional arguments may be interpreted by the shell rather than passed literally to `scanner.py`. The keyword placeholder is enclosed in double quotes, but this does not provide a security boundary. An attacker can include a double quote to terminate the quoted argument and then append shell syntax. The instructions do not require allowlist validation, escaping, or invocation through a non-shell argument array. Although `argparse` safely processes arguments after Python starts, it cannot protect against commands interpreted by the shell before `scanner.py` is launched. ### Attack Path 1. An attacker submits a stock-analysis or news reque ...[truncated 1482 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Do not construct shell command strings from user-derived values. 2. Invoke Python with a discrete argument array and without a shell, equivalent to: ```python subprocess.run( [ "python3", "/home/hoang/.openclaw/workspace/vn-stock-scanner/scripts/scanner.py", "ticker", "--ticker", ticker, ], shell=False, check=True, ) ``` 3. Validate tickers before invocation using a strict allowlist, such as uppercase ASCII letters and digits with a conservative maximum length: ```python if not re.fullmatch(r"[A-Z0-9]{1,10}", ticker): raise ValueError("Invalid ticker") ``` 4. Pass news keywords as a discrete argument rather than interpolating them into a quoted command. 5. Add defense-in-depth validation inside `scanner.py`, because callers other than the Skill may invoke it. 6. Update `SKILL.md` to explicitly prohibit shell interpolation and require structured process execution. 7. Run the scanner with a minimally privileged account and restrict access to credentials and sensitive files. ]]>
