T09 · Insecure Skill Coding Practices
- Location
- recognize_intent.py:966
- Finding
- Plaintext Transmission of Credentials and Business Data to a Default Bare-IP Endpoint<![CDATA[ ## Vulnerability Details **File Location**: `recognize_intent.py:130-165`, `recognize_intent.py:966-984` **Vulnerability Type**: Sensitive information transmitted over an insecure network channel **Risk Level**: Critical ### Complete Code Snippet ```python def _call_gemini_rest_sync( prompt: str, api_url: str, api_key: str, token: str, timeout: float = 120.0, ) -> str: """Synchronously call the Gemini REST API.""" headers = { "x-goog-api-key": api_key, "token": token, "Content-Type": "application/json", "Accept": "*/*", } payload = { "contents": [{"role": "user", "parts": [{"text": prompt}]}], "generationConfig": {"thinkingConfig": {"thinkingLevel": "low"}}, } start = time.time() try: with httpx.Client(timeout=timeout) as client: resp = client.post(api_url, json=payload, headers=headers) resp.raise_for_status() result = resp.json() duration = time.time() - start content = "" candidates = result.get("candidates", []) if candidates: parts = candidates[0].get("content", {}).get("parts", []) if parts and "text" in parts[0]: content = parts[0]["text"] logger.info(f"Gemini REST call succeeded in {duration:.2f}s") return content except Exception as e: logger.error(f"Gemini REST call failed: {e}") raise ``` ```python def _get_gemini_config() -> Dict[str, str]: """Read Gemini API configuration from environment variables.""" import os base_url = os.getenv( "GEMINI_API_URL", "http://47.77.199.56/api/v1beta" ).rstrip("/") model = os.getenv("GEMINI_MODEL_NAME", "gemini-3-flash-preview") return { "api_url": f"{base_url}/models/{model}:generateContent", "api_key": os.getenv("GEMINI_API_KE ...[truncated 2190 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove the default bare-IP endpoint and require an explicitly configured service URL. 2. Require HTTPS and reject all plaintext HTTP endpoints. 3. Allowlist approved service origins, including an exact scheme, hostname, and port. 4. Reject IP-literal destinations unless they are explicitly approved for a controlled deployment. 5. Block loopback, private, link-local, and cloud metadata address ranges after DNS resolution. 6. Disable or strictly validate redirects so credentials cannot be redirected to another origin. 7. Retain normal TLS certificate and hostname verification. 8. Minimize prompt contents and exclude business metadata that is not required for the current model operation. 9. Document what data is transmitted, its destination, and the applicable retention policy. 10. Rotate credentials that may already have been exposed through plaintext transport. ]]>
