T09 · Insecure Skill Coding Practices
Error
- Location
- image_to_code.py:42
- Finding
- Hardcoded Baidu OCR Credentials Exposed in Source Code<![CDATA[ ## Vulnerability Details **File Location**: `image_to_code.py`, lines 42-50 **Vulnerability Type**: Hardcoded API credentials **Risk Level**: High ### Vulnerable Code ```python self.baidu_api_key = None self.baidu_secret_key = None self.baidu_access_token = None # Baidu OCR configuration if self.use_baidu_ocr: self.baidu_api_key = "4LceeJ8wBDSqa3SqDHmgXuk1" self.baidu_secret_key = "nIulIWxqaUtY5XyfexSvP4OL8ZBk0krR" self._init_baidu_ocr() ``` The embedded credentials are subsequently submitted to the Baidu OAuth endpoint: ```python url = "https://aip.baidubce.com/oauth/2.0/token" params = { "grant_type": "client_credentials", "client_id": self.baidu_api_key, "client_secret": self.baidu_secret_key } response = requests.post(url, params=params, timeout=10) result = response.json() ``` ### Technical Analysis API credentials are stored directly in distributable source code. Any user who can download, inspect, or otherwise access the Skill package can recover the key and secret without authorization. Hardcoded secrets cannot be isolated per installation and cannot be rotated without modifying or redistributing the application. Because the OAuth flow uses the credentials to acquire an access token, possession of the source values may enable third parties to authenticate against the associated Baidu account within the permissions granted to that application. The documentation reinforces that the credentials are intentionally distributed by stating that the API key is built in. Although this supports convenient configuration, it violates secure secret-management practices and is not necessary for image conversion. ### Attack Path 1. An attacker obtains a copy of the Skill package. 2. The attacker reads `image_to_code.py` and extracts the API key and secret. 3. The attacker submits the credentials to the configured Baidu OAuth token endpoint. 4. If the credentials remain active, Baidu returns an access token. 5. The attacker ...[truncated 814 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Revoke and rotate the exposed Baidu credentials immediately. 2. Remove all credentials from source code, documentation, examples, test fixtures, and version history. 3. Require users to supply their own credentials through environment variables or a secret manager, for example: ```python import os self.baidu_api_key = os.environ.get("BAIDU_OCR_API_KEY") self.baidu_secret_key = os.environ.get("BAIDU_OCR_SECRET_KEY") ``` 4. Refuse to enable Baidu OCR when either credential is absent; do not silently substitute shared credentials. 5. Ensure error messages never print credentials, tokens, or complete authentication responses. 6. Apply least-privilege permissions and quota limits to the replacement application credentials. 7. Add automated secret scanning to the development and release process. 8. Review repository history and released artifacts because removing a secret from the latest file does not invalidate previously published copies. ]]>
