T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/test_nano_banana_2.py:84
- Finding
- Bearer Credential Can Be Disclosed to Response-Controlled Image Hosts## Vulnerability Details **File Location**: `scripts/test_nano_banana_2.py`, lines 84-91 and 358 **Vulnerability Type**: Credential disclosure through authenticated cross-origin requests **Risk Level**: High ### Vulnerable Code ```python def _extract_image_bytes(item: dict[str, Any], client: httpx.Client) -> bytes: if "b64_json" in item and isinstance(item["b64_json"], str): return base64.b64decode(item["b64_json"]) url_value = item.get("url") if isinstance(url_value, str) and url_value: resp = client.get(url_value, timeout=60) resp.raise_for_status() return resp.content ``` The client passed to this function is constructed with the API key as a default header and automatically follows redirects: ```python with httpx.Client(headers=_build_headers(api_key), follow_redirects=True) as client: ``` ### Technical Analysis The same `httpx.Client` is used both for authenticated API requests and for downloading image URLs supplied in the API response. `_build_headers()` installs the API key as the client's default `Authorization: Bearer` header. Because `_extract_image_bytes()` accepts an arbitrary URL from `data[0].url`, the authenticated client may send the bearer credential to a host selected by the API response. Automatic redirect following further increases the exposure surface because an initially trusted image URL may redirect to another origin. Image retrieval does not require the API authorization header and should be isolated from authenticated API traffic. Reusing the client therefore violates least-privilege networking principles. ### Attack Path 1. The user invokes text-to-image or image-to-image generation with a valid API key. 2. The configured API endpoint, a compromised upstream service, or an attacker-controlled endpoint returns a successful JSON response containing an external URL in `data[0].url`. 3. `_extract_image_bytes()` passes that URL to th ...[truncated 857 chars]
- Remediation
- ## Remediation Suggestions - Use one authenticated client exclusively for API calls and a separate client without default authorization headers for image downloads. - Do not copy the API key or any sensitive headers into download requests. - Require image download URLs to use HTTPS. - Validate the parsed hostname and port against an explicit allowlist of trusted image-delivery domains. - Disable redirects for image downloads or validate every redirect destination before following it. - Reject URLs containing user information, unusual ports, loopback addresses, link-local addresses, private network ranges, or non-HTTP schemes. - Prefer base64 image responses where supported so no secondary network request is required. - Add tests confirming that `Authorization` is absent from image-download requests and cross-origin redirects are rejected.
