T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/generate_image.py:53
- Finding
- API Credential Embedded in Request URL## Vulnerability Details **File Location**: `scripts/generate_image.py`, lines 53–57 **Vulnerability Type**: API credential exposure through a URL query parameter **Risk Level**: Medium **Vulnerable Code**: ```python if not api_url: api_url = os.environ.get("NEXTAI_API_URL", "https://generativelanguage.googleapis.com/v1beta") # Construct the request URL url = f"{api_url.rstrip('/')}/models/{model}:generateContent?key={api_key}" ``` ### Technical Analysis The API key is appended directly to the request URL as the `key` query parameter. URLs are commonly captured by reverse-proxy access logs, API gateway logs, monitoring systems, debugging tools, and server-side request telemetry. Consequently, a secret placed in the query string can persist in systems that would not normally record authorization headers. The destination is configurable through `NEXTAI_API_URL` or `--api-url`. If a user selects a third-party or attacker-controlled endpoint, the endpoint receives the complete request URL and therefore the API key. HTTPS protects the request in transit but does not protect the credential from the destination server or its logs. No key is hardcoded in the repository, and the script does not print the URL. Nevertheless, transmitting a secret in the URL unnecessarily expands its exposure. ### Attack Path 1. A user configures `NEXTAI_API_URL` or supplies `--api-url`, potentially following third-party relay guidance. 2. The script obtains the API key from an argument or environment variable. 3. The script appends the key to the generated request URL. 4. The destination server, reverse proxy, gateway, or monitoring system records the URL. 5. An operator or attacker with access to those logs extracts the API key. 6. The exposed key is used to issue unauthorized API requests until it is revoked or expires. ### Impact Assessment Exploitation can disclose the configured API credential. An attacker could consume the ...[truncated 387 chars]
- Remediation
- ## Remediation Suggestions - Prefer an authorization header supported by the selected API, such as `Authorization: Bearer ...` or the provider-specific API-key header, instead of a query parameter. - Separate official Gemini authentication from OpenAI-compatible relay authentication rather than applying one URL construction method to every endpoint. - Permit only HTTPS endpoints and reject cleartext HTTP URLs. - Warn users before transmitting credentials to a host other than an explicitly trusted official endpoint. - Redact query parameters and authorization values from exceptions, diagnostics, proxy logs, and application telemetry. - Use separate, narrowly scoped credentials for third-party relays and rotate any credential that may have appeared in logs.
