T09 · Insecure Skill Coding Practices
- Location
scripts/mit-learn.sh:87- Finding
Arbitrary Command Execution Through Unsafe file:// URL Decoding
- Content
View full analysis
/dev/null || echo "${path}") echo "$path" ``` ### Technical Analysis The value of `path` originates from a user-controlled `file://` argument and is interpolated directly into Python source code passed to `python3 -c`. Shell quoting does not make this safe at the Python-language level. An attacker can include a single quote, closing parentheses, Python statements, and a comment marker in the URL value. This terminates the intended string literal and introduces additional Python code. Conceptually, a malicious value shaped like the following can escape the intended expression: ```text file://x')); __import__('os').system(''); # ``` The resulting Python source executes the injected statement while `convert_file_url` is processing the argument. Execution occurs before the subsequent file-existence check, so the decoded path does not need to identify a valid local file. Both URL and file processing paths can reach this function when their values start with `file://`. ### Attack Path 1. An attacker persuades a user or automation system to invoke the Skill with a crafted `file://` source. 2. `cmd_add` identifies the value as a file URL and calls `convert_file_url`. 3. `convert_file_url` removes the `file://` prefix. 4. The remaining attacker-controlled string is inserted into the source supplied to `python3 -c`. 5. The injected Python statement invokes an operating-system command. 6. The command runs with the same operating-system identity and permissions as the user invoking the Skill. 7. The later `[ -f "${real_path}" ...[truncated 1163 chars]- Remediation
View remediation
