T09 · Insecure Skill Coding Practices
- Location
scripts/common.py:95- Finding
Unrestricted API Endpoint Can Expose the GoAI API Key and User Content
- Content
View full analysis
None: self.skill_name = skill_name self.base_url = os.environ.get("GOAI_BASE_URL", DEFAULT_BASE_URL).rstrip("/") self.api_key = os.environ.get("GOAI_API_KEY", "") self.last_payload: dict[str, Any] | None = None self.last_media_url = "" self._capabilities: dict[str, Any] | None = None self._http = httpx.Client( timeout=httpx.Timeout(60.0, connect=20.0), follow_redirects=True, ) ``` ```python def _headers(self, auth_mode: str) -> dict[str, str]: headers = {"Accept": "application/json"} if auth_mode == "auth": headers["Authorization"] = f"Bearer {self.api_key}" return headers ``` ```python def json_request( self, method: str, url: str, auth_mode: str, *, query: dict[str, Any] | None = None, body: dict[str, Any] | None = None, ) -> dict[str, Any]: try: response = self._http.request( method, url, headers=self._headers(auth_mode), params=query, json=body, ) ``` ### Technical Analysis `GOAI_BASE_URL` is accepted without validating its scheme or hostname. Authenticated API requests then attach `GOAI_API_KEY` as a bearer token to URLs derived from that value. Consequently, a mistaken, malicious, or externally influenced environment configuration can redirect authenticated requests to an attacker-controlled server. The implementation also permits plaintext `http://` endpoints and enables automatic redirects. This creates two related risks: 1. The bearer credential may be sent directly to an untrusted or plaintext ...[truncated 1720 chars]- Remediation
View remediation
