T09 · Insecure Skill Coding Practices
Warning
- Location
- SKILL.md:28
- Finding
- Gemini API Key Exposed Through Command-Line Arguments<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md:28`; related implementation in `index.js:189-195` **Vulnerability Type**: Command-line credential exposure **Risk Level**: Medium ### Vulnerable Code `SKILL.md:28`: ```bash node skills/image-scanner-pro/index.js --path <directory-path> --api-key <Gemini-Key> --output report.json ``` `index.js:189-195`: ```js const apiKeyIndex = args.indexOf('--api-key'); const proxyIndex = args.indexOf('--proxy'); const modelIndex = args.indexOf('--model'); const outputIndex = args.indexOf('--output'); const dirPath = pathIndex !== -1 ? args[pathIndex + 1] : '.'; const apiKey = apiKeyIndex !== -1 ? args[apiKeyIndex + 1] : process.env.GEMINI_API_KEY; ``` ### Technical Analysis The documented usage instructs users to provide the Gemini API key as a command-line argument. The implementation then retrieves that credential directly from `process.argv`. Command-line arguments are not an appropriate secret-transport mechanism. Depending on the operating system and execution environment, they may be exposed through: - Shell history files. - Process inspection tools and process listings. - `/proc` process metadata on supported systems. - CI/CD command logs. - Terminal recording and diagnostic telemetry. - Wrapper scripts or job-management interfaces that retain submitted commands. Although the application does not print the key itself, accepting and documenting `--api-key` unnecessarily exposes it outside the process. ### Attack Path 1. A user follows the documented command and supplies a valid Gemini API key using `--api-key`. 2. The shell records the complete command in its history, or the operating system exposes the argument through process metadata while the program is running. 3. A local user, support process, monitoring agent, or party with access to CI/CD logs reads the argument. 4. The party extracts the Gemini API key. 5. The stolen credential is used to submit requests to the Gemini API until it is re ...[truncated 821 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove `--api-key` from the documented command and from the command-line parser. 2. Prefer the existing `GEMINI_API_KEY` environment-variable mechanism: ```bash export GEMINI_API_KEY='...' node skills/image-scanner-pro/index.js --path <directory-path> --output report.json ``` 3. For interactive use, obtain the key through a hidden prompt that does not echo input or retain it in shell history. 4. For production and CI/CD environments, load the credential from a dedicated secret manager and inject it only into the child process environment. 5. Ensure CI/CD systems mask the environment variable and prevent it from appearing in debug output. 6. Never include the key in reports, exception messages, process titles, or diagnostic logs. 7. Rotate any key that has previously been supplied through the documented `--api-key` option. 8. Apply API-side restrictions, quotas, and monitoring to reduce the impact of future credential exposure. ]]>
