T09 · Insecure Skill Coding Practices
- Location
scripts/radio.sh:39- Finding
Path Traversal Outside the Skill Directory Enables Unintended Code Execution and Process Termination
- Content
View full analysis
"$PID_FILE" sleep 1.5 ``` ```bash cmd_stop() { if ! is_running; then echo "Kannaka Radio is not running" return 0 fi local pid pid=$(cat "$PID_FILE") kill "$pid" 2>/dev/null && echo "Stopped (PID $pid)" || echo "Already stopped" rm -f "$PID_FILE" } ``` ### Technical Analysis The script assumes that the repository root is three parent directories above the Skill directory. That assumption is incompatible with the supplied package layout. For the audited installation path, traversing three parents from the `artifact` directory resolves to the filesystem root: ```text artifact/.. -> package temporary directory artifact/../.. -> /tmp artifact/../../.. -> / ``` Consequently, the effective paths become: ```text SERVER_JS=/server/index.js PID_FILE=/.radio.pid ``` The wrapper therefore does not execute a server bundled with the Skill. Instead, it attempts to execute an unrelated JavaScript file outside the Skill's trust boundary. It also reads, creates, and deletes a PID file at an external location. No `server/index.js` exists in the audited package, so this behavior is not necessary for the declared radio functionality. It ...[truncated 2217 chars]- Remediation
View remediation
&2 exit 1 fi ``` 4. Validate the PID file before using it: ```bash read_pid() { [[ -f "$PID_FILE" && ! -L "$PID_FILE" ]] || return 1 local pid IFS= read -r pid < "$PID_FILE" [[ "$pid" =~ ^[1-9][0-9]*$ ]] || return 1 printf '%s\n' "$pid" } ``` 5. Before signaling a process, verify that its executable and command line correspond to the expected Node server. On Linux, compare `/proc/$pid/cmdline` and `/proc/$pid/exe` with the expected command. Refuse to signal the process if verification fails. 6. Write the PID file atomically and prevent symbolic-link attacks by creating it in a private runtime directory. Remove it only after confirming that it is the Skill's own PID file. 7. Do not run this wrapper as root or with elevated privileges. 8. Include the advertised `server/index.js` and supporting package files in the Skill package so the implementation can be audited and executed without relying on files outside the package. ]]>
