T09 · Insecure Skill Coding Practices
Error
- Location
- audio_summary_skill.py:7
- Finding
- Hard-Coded DashScope API Credential<![CDATA[ ## Vulnerability Details **File Location**: `audio_summary_skill.py`, lines 7-13 **Vulnerability Type**: Hard-coded secret **Risk Level**: High ### Vulnerable Code ```python API_KEY = 'sk-76735bc919a549a7a643f6b401815840' BASE_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1" client = OpenAI( api_key=API_KEY, base_url=BASE_URL, ) ``` ### Technical Analysis A complete Alibaba Cloud DashScope API key is embedded directly in the source code. Anyone who can read the project files, a distributed skill package, a source archive, or repository history can recover and reuse this credential independently of the skill. Hard-coded credentials cannot be securely rotated per deployment and are likely to leak through version-control history, backups, logs, or copied project artifacts. Removing the key only from the current version would not invalidate copies that have already been exposed. ### Attack Path 1. An attacker obtains read access to the project, its source archive, or repository history. 2. The attacker extracts the API key from line 7. 3. The attacker configures an API client to use the documented DashScope endpoint. 4. Requests are submitted under the identity, quota, and billing scope associated with the exposed key. 5. The attacker continues using the credential until it is revoked or restricted by the provider. ### Impact Assessment Successful exploitation does not directly grant local operating-system privileges. It grants whatever remote API permissions are assigned to the exposed key. Potential consequences include: - Unauthorized use of paid model services. - Consumption or exhaustion of API quotas. - Charges being attributed to the credential owner. - Disruption of legitimate transcription requests. - Access to other API operations if the key has broader permissions than those required by this skill. The precise cloud-side scope depends on the provider configuration and cannot be determined from the reviewed files. ]]>
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Revoke and rotate the exposed key immediately; changing the source code alone does not invalidate leaked copies. 2. Remove the credential from the source tree and purge it from repository history and distributed artifacts where feasible. 3. Obtain the key at runtime from a protected environment variable or secrets manager: ```python API_KEY = os.environ.get("DASHSCOPE_API_KEY") if not API_KEY: raise RuntimeError("DASHSCOPE_API_KEY is not configured") ``` 4. Grant the replacement key only the minimum API permissions required for transcription. 5. Apply provider-side spending limits, quotas, expiration, source restrictions, and monitoring where supported. 6. Add secret scanning to pre-commit hooks and continuous integration. 7. Avoid logging credentials or including them in documentation and example configuration files. ]]>
