T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/deep_research.py:118
- Finding
- Gemini API Key Exposed Through Command-Line Arguments<![CDATA[ ## Vulnerability Details **File Location**: `scripts/deep_research.py`, lines 118-123 **Vulnerability Type**: Sensitive credential exposure through process arguments **Risk Level**: Medium ### Vulnerable Code ```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 provide a Gemini API key through the `--api-key` command-line option. Command-line arguments are not an appropriate secret-transport mechanism because they may be: - Retained in shell history. - Captured by process monitoring or observability systems. - Visible through process inspection facilities to other authorized local users. - Included in diagnostic reports, terminal transcripts, or automation logs. Environment-based authentication is already supported, so accepting the same credential through a process argument unnecessarily increases its exposure. The script does not intentionally print or persist the key, and no evidence of transmission to an undeclared endpoint was found; the key is sent only to the documented Google Gemini API in the `x-goog-api-key` header. ### Attack Path 1. A user invokes the script with a command such as: ```bash scripts/deep_research.py --query "Research topic" --api-key "SECRET" ``` 2. The command and API key are retained in shell history, captured in logs, or exposed through local process inspection. 3. A local user or monitoring component with access to that information retrieves the key. 4. The exposed key is reused against Gemini API services within the permissions and quota associated with that credential. ### Impact Assessment Successful exploitation can disclose the Gemini API key. An attacker could use the credential to consume the associated API quota, incur costs, or access API resources authorized for that key. This issue does no ...[truncated 150 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Remove the `--api-key` command-line option. - Prefer the existing `GEMINI_API_KEY` environment variable or an operating-system credential manager. - If interactive entry is required, use `getpass.getpass()` so the credential is not echoed or placed in shell history. - For automation, support a permission-restricted credential file and validate that its permissions prevent access by unauthorized users. - Ensure application, shell, and CI/CD logs never include the credential. - Rotate any API key that has previously been supplied through the command line. ]]>
