T09 · Insecure Skill Coding Practices
Error
- Location
- image_gen.py:14
- Finding
- Hard-Coded API Credential Exposed in Source Code## Vulnerability Details **File Location**: `image_gen.py`, lines 14-24 **Vulnerability Type**: Hard-coded secret and insecure credential management **Risk Level**: High ### Vulnerable Code ```python API_KEY = "sk-hJP0yrKv2H7A4mjy39D8C3D5Dd17492494A65f4bCbE9859e" BASE_URL = "https://jyapi.AI-WX.CN" def generate_image(prompt, model="gpt-image-1.5", size="1024x1024", n=1, image=None): url = f"{BASE_URL}/v1/images/generations" headers = { "Authorization": API_KEY, "Content-Type": "application/json" } ``` ### Technical Analysis A live-looking API credential is embedded directly in the distributed Python source and transmitted in the authorization header on every generation request. Anyone who can read the Skill package can extract and reuse the credential outside the intended application. Authentication is necessary for the declared image-generation functionality, but embedding a shared credential in source code is not necessary and violates least-privilege credential-management practices. The key cannot be isolated per user, rotated without changing the package, or protected using filesystem or secret-manager controls. ### Attack Path 1. An attacker obtains or reads the Skill package. 2. The attacker extracts the `API_KEY` value from `image_gen.py`. 3. The attacker sends independent requests to the configured API using the extracted authorization value. 4. Requests are attributed to the exposed credential until the service revokes or rotates it. ### Impact Assessment Exploitation may permit unauthorized use of the API account associated with the credential. The scope includes consumption of API quota, potential billing impact, service abuse, rate-limit exhaustion, and loss of reliable request attribution. The exposed key does not directly grant local system privileges, but it grants whatever remote API permissions are assigned to that credential.
- Remediation
- ## Remediation Suggestions 1. Immediately revoke and rotate the exposed credential. 2. Remove all credentials from source code and repository history. 3. Read the credential from a protected environment variable or secret manager: ```python API_KEY = os.environ.get("APIFOX_API_KEY") if not API_KEY: raise RuntimeError("APIFOX_API_KEY is not configured") ``` 4. Use a dedicated credential with only the permissions and quota required for image generation. 5. Prefer per-user or short-lived credentials instead of a shared package-level secret. 6. Add automated secret scanning to development and release workflows. 7. Confirm the API's required authorization scheme and use the documented header format.
