T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/setup.py:39
- Finding
- API Credentials May Be Transmitted to an Unvalidated Custom Endpoint<![CDATA[ ## Vulnerability Details **File Location**: `scripts/setup.py:39-41`; `scripts/productai_client.py:30-35` **Vulnerability Type**: Unvalidated credential destination **Risk Level**: Medium ### Vulnerable Code ```python # scripts/setup.py:39-41 api_endpoint = input("API Endpoint [https://api.productai.photo/v1]: ").strip() if not api_endpoint: api_endpoint = "https://api.productai.photo/v1" ``` ```python # scripts/productai_client.py:30-35 self.api_key = api_key self.api_endpoint = api_endpoint.rstrip('/') self.session = requests.Session() self.session.headers.update({ 'x-api-key': api_key, 'Content-Type': 'application/json' }) ``` ### Technical Analysis The setup process accepts an arbitrary API endpoint and stores it without validating its scheme, hostname, port, or embedded credentials. The client then attaches the ProductAI API key to every request made through its session. Although source image URLs are restricted to HTTPS, the configured API endpoint is not subject to equivalent validation. Consequently, it may use plaintext HTTP or point to an unrelated, attacker-controlled host. This creates a credential-disclosure risk because the `x-api-key` header is automatically transmitted to the configured destination. This is an insecure configuration-boundary issue rather than evidence of intentionally malicious behavior. ### Attack Path 1. An attacker persuades a user or administrator to enter an attacker-controlled URL as the API endpoint, or modifies an accessible configuration file. 2. The user invokes image generation, upscaling, or job-status functionality. 3. `ProductAIClient` creates a request to the configured endpoint. 4. The session automatically adds the victim's ProductAI API key as the `x-api-key` header. 5. The attacker-controlled server records the credential. 6. The attacker uses the captured key against the legitimate ProductAI API, subject to the key's permissions and service-side controls. If an HTTP endpoint i ...[truncated 485 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Require the endpoint to use HTTPS. 2. Allowlist the official ProductAI API hostname by default. 3. Reject URLs containing embedded user information, fragments, unexpected ports, or malformed hostnames. 4. If custom endpoints are a required feature, display a prominent warning and require explicit confirmation before transmitting credentials. 5. Repeat endpoint validation in `ProductAIClient.__init__` so manually created configuration files cannot bypass setup-time checks. 6. Consider separating credentials by destination and never attach the ProductAI key to hosts outside an explicit allowlist. 7. Document API-key rotation procedures for users who may have configured an untrusted endpoint. Example validation: ```python from urllib.parse import urlparse def validate_api_endpoint(endpoint: str) -> str: parsed = urlparse(endpoint) if parsed.scheme != "https": raise ValueError("The API endpoint must use HTTPS") if parsed.hostname != "api.productai.photo": raise ValueError("Untrusted API endpoint hostname") if parsed.username or parsed.password: raise ValueError("Embedded URL credentials are not allowed") if parsed.port not in (None, 443): raise ValueError("Unexpected API endpoint port") return endpoint.rstrip("/") ``` ]]>
