T09 · Insecure Skill Coding Practices
Error
- Location
- agent.py:5
- Finding
- Hardcoded Weather API Credential## Vulnerability Details **File Location**: `agent.py`, lines 5–7 **Vulnerability Type**: Hardcoded API credential and credential exposure in a URL **Risk Level**: High ```python #https://api.weather.com/v2/turbo/vt1dailyForecast?apiKey=c1ea9f47f6a88b9acb43aba7faf389d4&format=json&geocode=39.93%2C116.40&language=zh-CN&units=m api_key = "c1ea9f47f6a88b9acb43aba7faf389d4" url = f"https://api.weather.com/v2/{city}/{date}?key={api_key}" ``` ### Technical Analysis A Weather.com API key is embedded directly in the source code and is also exposed in a commented example URL. Anyone who can access the skill package or its source history can recover the credential without authentication. The implementation additionally places the key in the request query string. Although HTTPS protects the URL while it is in transit, query strings may be retained by application logs, reverse proxies, monitoring systems, debugging tools, or error reports. This unnecessarily expands the credential's exposure surface. ### Attack Path 1. An attacker obtains the distributed skill package or access to its source repository. 2. The attacker opens `agent.py` and extracts the API key from line 5 or line 6. 3. The attacker sends independent requests to Weather.com using the recovered credential. 4. Requests are attributed to the credential owner and consume the associated quota or billable usage. 5. If URLs are logged in deployed infrastructure, additional parties with log access may recover and reuse the same key. ### Impact Assessment Exploitation does not grant local operating-system privileges or code execution. Its scope is limited to the permissions and service entitlements assigned to the exposed Weather.com credential. A successful attacker may consume API quota, cause service disruption through quota exhaustion, create billing impact where usage is chargeable, and access any Weather.com operations authorized for that key.
- Remediation
- ## Remediation Suggestions 1. Revoke and rotate the exposed API key immediately; removing it from the current file does not invalidate copies already distributed. 2. Remove the key from executable code, comments, examples, repository history, build artifacts, and deployment logs. 3. Store the replacement credential in an environment variable or managed secret store and inject it only at runtime. 4. Use the authentication mechanism recommended by the API provider, preferably an authorization header rather than a query parameter when supported. 5. Restrict the replacement credential by permitted APIs, source addresses, environments, quotas, and spending limits where the provider supports such controls. 6. Add automated secret scanning to version-control and CI workflows to prevent future credential commits. 7. Ensure exceptions, request diagnostics, and observability systems redact authentication values and request URLs containing sensitive query parameters.
