T09 · Insecure Skill Coding Practices
Error
- Location
- ctl.js:211
- Finding
- Unescaped Regular Expression Allows Overbroad Process Termination## Vulnerability Details **File Location**: `ctl.js`, lines 211–216 **Vulnerability Type**: Improper neutralization of regular-expression metacharacters in process selection **Risk Level**: High ### Vulnerable Code ```js async function closeApp(appName) { const sanitizedApp = sanitizeAppName(appName); if (platform === 'linux' || platform === 'darwin') { // pkill -f pattern await execFilePromise('/usr/bin/pkill', ['-f', sanitizedApp]); ``` ### Technical Analysis On Linux and macOS, `closeApp()` supplies the user-controlled application name to `pkill -f`. Although `execFile` prevents shell-command injection, the argument is interpreted by `pkill` as a regular expression matched against complete process command lines. The validation performed by `sanitizeAppName()` permits dots, dashes, spaces, underscores, and alphanumeric characters. In particular, the permitted dot character is a regular-expression wildcard that matches any character. The validator therefore does not neutralize input for the downstream regular-expression interpreter. This also means benign short application names may match unrelated command lines because `-f` performs substring-style matching against the full command line rather than exact executable-name matching. ### Attack Path 1. An attacker or untrusted caller invokes the skill on Linux or macOS using `--action close_app --app .`. 2. `sanitizeAppName()` accepts `.` because dots are included in its allowlist. 3. `closeApp()` invokes `/usr/bin/pkill` with `['-f', '.']`. 4. `pkill` interprets `.` as a regular-expression wildcard. 5. The pattern matches nearly every non-empty process command line visible and signalable by the skill's operating-system user. 6. `pkill` terminates those matched processes, including unrelated applications and potentially components supporting the agent session. ### Impact Assessment Exploitation can cause denial of service and loss of unsave ...[truncated 308 chars]
- Remediation
- ## Remediation Suggestions Avoid passing an application identifier to a regular-expression process matcher. 1. Prefer exact executable-name matching, such as `pkill -x -- sanitizedApp`, after validating the expected executable-name format. 2. If full-command matching is operationally necessary, escape every regular-expression metacharacter before invoking `pkill`, anchor the resulting expression to the intended command structure, and include `--` before the pattern where supported. 3. Reject ambiguous identifiers such as `.`, names consisting only of punctuation, and excessively broad short patterns. 4. Consider enumerating processes first, comparing parsed executable paths or names literally, and terminating only explicitly identified process IDs. 5. Add regression tests demonstrating that inputs such as `.`, `..`, and short substrings cannot select unrelated processes. 6. Update the security documentation to distinguish shell metacharacter protection from regular-expression metacharacter protection.
