T09 · Insecure Skill Coding Practices
Error
- Location
- SKILL.md:51
- Finding
- Shell command injection through unvalidated port and service-name arguments<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md`, lines 51-64, 95-99, and 123-128 **Vulnerability Type**: Command injection caused by unsafe shell argument construction **Risk Level**: High ### Vulnerable Code ```bash meshlink agent-status meshlink check-port --port <port> ``` ```bash meshlink publish --name <service_name> --port <port> ``` ```bash meshlink unpublish --name <name> ``` ### Technical Analysis The Skill directs the agent to insert port numbers and service names into Bash command templates. It does not require strict validation of the user-provided port or the name accepted by the unpublish workflow. Publication names generated during the normal publishing flow are restricted to lowercase kebab-case. However, this restriction is not explicitly applied to the independently invoked unpublish command. Port input also lacks a required numeric type check and range check. If these templates are executed through a shell after direct string substitution, shell metacharacters in an attacker-controlled value can terminate or extend the intended command. For example, a port value such as `3000; id > /tmp/meshlink-proof` could cause the shell to run both the intended `meshlink` command and the injected command. The vulnerability depends on the agent or command-execution layer constructing a shell command from the template rather than passing arguments as a structured argument array. The Skill does not mandate the safer execution method. ### Attack Path 1. An attacker asks the agent to publish a service and supplies a crafted port value containing a valid-looking port followed by a shell separator and an operating-system command. 2. The Skill directs the agent to insert that value into `meshlink check-port --port <port>`. 3. If the agent executes the resulting text through Bash, the shell interprets the separator. 4. The injected command executes with the same operating-system privileges as the agent. 5. Alternatively, the attacker re ...[truncated 693 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Validate every port before command execution: - Accept decimal digits only. - Parse the value as an integer. - Require a range of `1` through `65535`. - Reject whitespace, signs, shell metacharacters, and trailing content. 2. Validate every service name, including names supplied to `unpublish`, against an allowlist such as: ```regex ^[a-z0-9]+(?:-[a-z0-9]+)*$ ``` 3. Use a process-execution API that accepts an executable and an argument array, for example: ```text executable: meshlink arguments: ["check-port", "--port", validatedPort] ``` Do not construct a single command string for evaluation by Bash. 4. If shell execution is unavoidable, apply robust shell escaping after validation. Escaping must not replace allowlist validation. 5. Add explicit instructions stating that user input must never be interpreted as flags or shell syntax. Where supported, use an end-of-options delimiter before positional user-controlled values. 6. Add negative tests covering semicolons, command substitution, pipes, redirection operators, newlines, leading hyphens, whitespace, and out-of-range ports. ]]>
