T09 · Insecure Skill Coding Practices
Error
- Location
- assets/backend/app.py:23
- Finding
- Unrestricted API Destination Can Disclose Uploaded Images and API Credentials<![CDATA[ ## Vulnerability Details **File Location**: `assets/backend/app.py:23-25, 159-175` **Vulnerability Type**: Unvalidated outbound API destination and sensitive-data disclosure **Risk Level**: High ### Vulnerable Code ```python STEPFUN_API_KEY = os.getenv("STEPFUN_API_KEY", "") STEPFUN_BASE_URL = os.getenv("STEPFUN_BASE_URL", "https://api.stepfun.com/v1") STEPFUN_EDIT_URL = f"{STEPFUN_BASE_URL}/images/edit" ``` ```python # Call StepFun API image_b64 = image_to_base64(upload_path) headers = { "Authorization": f"Bearer {STEPFUN_API_KEY}", "Content-Type": "application/json", } payload = { "model": "step-image-edit-2", "image": image_b64, "prompt": prompt, "response_format": "b64_json", } try: resp = requests.post(STEPFUN_EDIT_URL, json=payload, headers=headers, timeout=120) ``` ### Technical Analysis The backend obtains the outbound API base URL directly from the process environment and does not validate its scheme, hostname, port, or resolved IP address. It then sends both the uploaded image and the `STEPFUN_API_KEY` bearer credential to that destination. The Skill only documents two legitimate StepFun endpoint prefixes. Allowing an arbitrary destination exceeds the minimum network privileges required for the declared image-editing functionality. Base64 encoding itself is necessary for the documented StepFun JSON API and is not covert exfiltration. The security issue is that the encoded image and API credential can be sent to an unrestricted destination. Depending on `requests` redirect behavior, a malicious or compromised endpoint may also redirect the request. Sensitive authorization headers are normally removed on cross-host redirects, but redirects should still be disabled or explicitly validated because the image payload remains sensitive. ### Attack Path 1. An attacker gains the ability to modify the generated application's `.env`, deployment configuration, container environment, or process environment. 2. The ...[truncated 918 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Allowlist the exact documented StepFun hosts and HTTPS scheme. - Reject URLs containing user information, unexpected ports, fragments, or unsupported paths. - Resolve the hostname and reject loopback, private, link-local, multicast, and metadata-service addresses. - Disable redirects with `allow_redirects=False`, or validate every redirect destination before following it. - Construct the API URL from a fixed application-controlled host wherever possible. - Store the API key in a managed secret store and rotate it immediately if endpoint redirection is suspected. - Fail startup if the API key is absent rather than sending an empty bearer credential. - Log destination validation failures without logging the API key or image payload. ]]>
