T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/deep_research.py:112
- Finding
- Gemini API Key Exposure Through Command-Line Arguments## Vulnerability Details **File Location**: `scripts/deep_research.py`, lines 112 and 118 **Vulnerability Type**: Sensitive credential exposure through process arguments **Risk Level**: Medium ### Complete Code Snippet ```python parser.add_argument("--api-key", help="Gemini API key (overrides GEMINI_API_KEY env var)") args = parser.parse_args() # Get API key api_key = args.api_key or os.environ.get("GEMINI_API_KEY") ``` ### Technical Analysis The script permits users to supply a Gemini API key through the `--api-key` command-line argument. Command-line arguments are not an appropriate secret-transport mechanism because they can be recorded in shell history, captured by process-monitoring or observability software, included in diagnostic logs, and potentially viewed through operating-system process inspection. The script otherwise sends the key as an authentication header over HTTPS to a fixed official Google API endpoint. The vulnerability concerns local exposure before or during execution, not plaintext network transmission or transmission to an unrelated destination. ### Attack Path 1. A user runs the script with a command such as: ```bash python scripts/deep_research.py --query "research topic" --api-key "SECRET" ``` 2. The complete invocation is retained in shell history, process telemetry, job-runner logs, or an operating-system process listing. 3. A local user, monitoring agent, log reader, or other process with access to that data retrieves the API key. 4. The exposed key is reused against Gemini API services until it is revoked or restricted. ### Impact Assessment An attacker who recovers the key may consume the associated API quota, generate charges where billing applies, impersonate the authorized client, and access API resources permitted by the key's configuration. This issue does not independently grant local privilege escalation or unrestricted system access. Its scope is bounded by ...[truncated 87 chars]
- Remediation
- ## Remediation Suggestions 1. Remove the `--api-key` option and obtain the credential from `GEMINI_API_KEY`, an operating-system secret store, or a protected credential file. 2. For interactive use, support secret input through `getpass.getpass()` or standard input without echoing the value. 3. If command-line compatibility must temporarily remain, emit a prominent security warning and mark the option as deprecated. 4. Ensure surrounding automation does not print environment variables, request headers, or secret-bearing command lines. 5. Apply server-side API-key restrictions, quota limits, and least-privilege controls. 6. Rotate any key that has previously been passed on the command line and remove affected entries from shell histories and execution logs.
