T09 · Insecure Skill Coding Practices
- Location
scripts/deep_research.py:112- Finding
Gemini API Key Exposure Through Command-Line Arguments
- Content
View full analysis
Vulnerability Details
File Location:
scripts/deep_research.py, lines 112 and 118
Vulnerability Type: Sensitive credential exposure through process arguments
Risk Level: MediumComplete 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-keycommand-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
- A user runs the script with a command such as:
bash python scripts/deep_research.py --query "research topic" --api-key "SECRET" - The complete invocation is retained in shell history, process telemetry, job-runner logs, or an operating-system process listing.
- A local user, monitoring agent, log reader, or other process with access to that data retrieves the API key.
- 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]
- A user runs the script with a command such as:
- Remediation
View remediation
Remediation Suggestions
- Remove the
--api-keyoption and obtain the credential fromGEMINI_API_KEY, an operating-system secret store, or a protected credential file. - For interactive use, support secret input through
getpass.getpass()or standard input without echoing the value. - If command-line compatibility must temporarily remain, emit a prominent security warning and mark the option as deprecated.
- Ensure surrounding automation does not print environment variables, request headers, or secret-bearing command lines.
- Apply server-side API-key restrictions, quota limits, and least-privilege controls.
- Rotate any key that has previously been passed on the command line and remove affected entries from shell histories and execution logs.
- Remove the
