T09 · Insecure Skill Coding Practices
- Location
scripts/data-collector.mjs:39- Finding
OS Command Injection Through Unsanitized City Input
- Content
View full analysis
/dev/null || echo '{}'`; const output = execSync(cmd, { encoding: 'utf8', timeout: 10000 }); ``` The `city` value originates from the exported `getWeather(city)` API and can also be supplied through higher-level exported functions such as `generateBriefing({ city })`. ### Technical Analysis The application constructs a shell command by directly interpolating the `city` argument into a single-quoted URL and then passes the resulting string to `execSync()`. No allowlist validation, shell escaping, or safe argument separation is applied. Because `execSync()` invokes a shell for a string command, an attacker can supply a city value containing a single quote to terminate the quoted URL, followed by shell metacharacters and an arbitrary command. The trailing portion of the original command can then be neutralized with a shell comment or otherwise incorporated into the injected command. This vulnerability is reachable through the project's public JavaScript API even though the current command-line interface does not expose a city argument directly. ### Attack Path 1. An application imports `getWeather()`, `generateBriefing()`, or another API that accepts the `city` option. 2. The application passes a city value influenced by an untrusted user. 3. The malicious value closes the single-quoted URL and appends an operating-system command. 4. `getWeather()` incorporates the value into the shell command without validation. 5. `execSync()` executes the resulting command under the identity and privileges of the Node.js process. 6. The injected command can access any files, environment variables, credentials, or network resources available to that process. Conceptually, an input shaped like the following demonstrates the injectio ...[truncated 860 chars]- Remediation
View remediation
