T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/get_coupon.py:21
- Finding
- Obfuscated Hardcoded API Credential Transmitted to a Third-Party Service<![CDATA[ ## Vulnerability Details **File Location**: `scripts/get_coupon.py`, lines 21–47 and 95–114 **Vulnerability Type**: Hardcoded credential, concealed network destination, and sensitive credential transmission **Risk Level**: High ### Vulnerable Code ```python def _get_api_config(self): url_part1 = "aHR0cHM6Ly9vcGVuLmRhdGFkZXguY29tLmNuL2RleHNlcnZlci9kZXgtYXBpL3Yx" url_part2 = "L2dldGNvdXBvbg==" a1_part1 = "QVBQLVZFTm1FdjAtOTM4MTAy" a1_part2 = "MjQ5MTI5OTE0NDMzLTEx" a2_part1 = "S0VZMDM1VkVObkhzeA==" a2_part2 = "MkIzOTQ5SWdNRWZuYVI0QldZR3Q5M3BlZE1rd3BRMHYxMg==" api_base = base64.b64decode(url_part1).decode() + base64.b64decode(url_part2).decode() a1 = base64.b64decode(a1_part1).decode() + base64.b64decode(a1_part2).decode() a2 = base64.b64decode(a2_part1).decode() + base64.b64decode(a2_part2).decode() ts = str(int(time.time())) token = hashlib.md5(f"api_{ts}".encode()).hexdigest()[:8] return { 'url': api_base, 'a1': a1, 'a2': a2, 't1': ts, 'token': token } ``` ```python config = self._get_api_config() api_url = config['url'] payload = { 'a1': config['a1'], 'a2': config['a2'], 't1': config['t1'] } req = urllib.request.Request( api_url, data=json.dumps(payload).encode('utf-8'), headers={ 'Content-Type': 'application/json', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36', 'Accept': 'application/json', 'X-Token': config['token'] }, method='POST' ) resp = urllib.request.urlopen(req, timeout=10) ``` ### Technical Analysis The program embeds a reusable application identifier and API key directly in distributed client code. The endpoint and credentials are split into fragments and Base64-decoded at runtime. Base64 is reversible encoding rather than encryption and offers no confidentiality. Anyone who can access the Skill package can reconstruct the endpoint and credentia ...[truncated 2008 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove the application ID and API key from the distributed Skill source, including encoded fragments and plaintext comments. 2. Do not treat Base64 or string splitting as secret protection. 3. Keep reusable provider credentials on a controlled backend and expose only a narrowly scoped coupon-query interface to clients. 4. If users must authenticate directly, load credentials from a protected secret manager or environment-based secret injection mechanism rather than source control. 5. Prefer short-lived, audience-restricted, least-privilege tokens over a shared permanent key. 6. Rotate and revoke the exposed credential because it must be considered compromised once distributed. 7. Document the third-party endpoint and the exact request fields sent over the network. 8. Replace the predictable truncated MD5 token scheme with a provider-supported authentication mechanism, such as a server-issued short-lived token or an HMAC using a secret that is not shipped to clients. 9. Apply provider-side rate limiting, usage monitoring, credential scoping, and anomaly alerts. ]]>
