T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/duplicate_checker.py:23
- Finding
- License API Key Exposure Through Command-Line Arguments and External Transmission<![CDATA[ ## Vulnerability Details **File Location**: `scripts/duplicate_checker.py:23-50, 394-409` **Vulnerability Type**: Credential exposure and insecure secret handling **Risk Level**: Medium ### Vulnerable Code ```python VERIFY_URL = "https://api.yk-global.com/v1/verify" def verify_api_key(api_key: str) -> tuple[bool, str]: if not api_key: return False, "FREE" try: req = urllib.request.Request( VERIFY_URL, method="POST", headers={ "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" }, data=b"{}", ) with urllib.request.urlopen(req, timeout=10) as resp: data = json.loads(resp.read().decode("utf-8")) ``` ```python api_key = "" if len(sys.argv) > 3: arg3 = sys.argv[3] if arg3.startswith("inv-") or arg3.startswith("IN"): api_key = arg3 else: tier_data = json.loads(arg3) monthly_count = tier_data.get("monthly_count", 0) api_key = tier_data.get("api_key", "") if len(sys.argv) > 4 and not api_key: api_key = sys.argv[4] tier = TierConfig.from_api_key(api_key, monthly_count) ``` ### Technical Analysis The script accepts a license API key directly through command-line arguments and sends it as a bearer token to the vendor-controlled `api.yk-global.com` endpoint. External license validation is related to the declared tier-control functionality and does not, by itself, exceed the functional privilege requirements. However, command-line arguments are not an appropriate secret transport mechanism. Depending on the operating environment, arguments may be exposed through: - Process inspection tools such as `ps`. - Shell history. - Process telemetry and audit logging. - Container or orchestration diagnostics. - Parent-process logs and error reports. The network request uses HTTPS, and the audited code does not send invoice records in this request. Never ...[truncated 1027 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove API-key support from positional command-line arguments. 2. Read the credential from a protected environment variable, secret manager, or non-echoing standard-input prompt. 3. If environment variables are used, ensure they are not printed in diagnostics or inherited by unnecessary child processes. 4. Add an explicit offline mode that performs local duplicate checking without contacting the vendor. 5. Clearly document the destination, purpose, and data included in the verification request. 6. Validate the response status, content type, maximum size, and expected JSON schema. 7. Avoid caching complete secret strings where possible; use a keyed or one-way identifier for cache indexing. 8. Support credential revocation and rotation in case a key is exposed. ]]>
