T09 · Insecure Skill Coding Practices
- Location
scripts/serper_image_search.py:145- Finding
Environment-Controlled Endpoint Can Expose API Credentials and Search Queries
- Content
View full analysis
Vulnerability Details
File Location:
scripts/serper_image_search.py, lines 68-77 and 145-147
Vulnerability Type: Arbitrary credential-bearing network destination
Risk Level: HighVulnerable Code
python def _post_json(url: str, payload: dict[str, Any], api_key: str) -> dict[str, Any]: body = json.dumps(payload).encode("utf-8") req = request.Request( url, data=body, headers={ "Content-Type": "application/json", "X-API-KEY": api_key, }, method="POST", )python base_url = os.environ.get("SERPER_BASE_URL", DEFAULT_BASE_URL).rstrip("/") payload = _build_payload(args) data = _post_json(f"{base_url}/images", payload, api_key)Technical Analysis
The script permits
SERPER_BASE_URLto override the intended Serper endpoint without validating the URL scheme or hostname. The_post_jsonfunction then unconditionally includes the value ofSERPER_API_KEYin theX-API-KEYrequest header.Sending the API key and search query to the default
https://google.serper.dev/imagesendpoint is necessary for the declared image-search functionality. Allowing an arbitrary environment-selected destination to receive the same credential is not necessary and exceeds the minimum network privileges required by the Skill.An actor who can influence the process environment can configure an attacker-controlled HTTP or HTTPS endpoint. The script will submit both the API credential and user-provided query to that endpoint. Permitting an HTTP URL can additionally expose these values to passive or active network interception.
Attack Path
- An attacker or compromised launcher gains the ability to define environment variables for the Skill process.
- The attacker sets
SERPER_BASE_URLto a server under their control, such ashttps://attacker.example. - A user or agent invokes the documented image-search com ...[truncated 1130 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove the
SERPER_BASE_URLoverride if custom endpoints are not required. - If configurability is necessary, parse the URL with
urllib.parse.urlparseand require:- The
httpsscheme. - An exact allowlisted hostname, normally
google.serper.dev. - No embedded username or password.
- The expected port, or no explicit port.
- The
- Construct the endpoint from a trusted constant rather than concatenating credentials with an arbitrary environment-provided origin.
- Ensure authorization headers are never forwarded across redirects to a different origin. Prefer rejecting redirects or validating every redirect destination before resending credentials.
- Fail closed with a clear error when URL validation fails.
- Add tests proving that HTTP URLs, lookalike domains, subdomain tricks, embedded credentials, and non-allowlisted hosts are rejected.
- Remove the
