T09 · Insecure Skill Coding Practices
- Location
scripts/weather_query.py:105- Finding
API Credential Exposed in Request URL
- Content
View full analysis
Vulnerability Details
File Location:
scripts/weather_query.py, lines 105–108
Vulnerability Type: API credential exposure through URL query parameters
Risk Level: Mediumpython endpoint = endpoints.get(weather_type, "/v7/weather/now") url = f"{API_BASE_URL}{endpoint}?location={city_id}&key={api_key}" try: resp = requests.get(url, timeout=10)Technical Analysis
The QWeather API key is embedded directly in the URL query string. Although HTTPS protects the request while it is in transit, query strings are commonly recorded by HTTP clients, proxies, gateways, monitoring systems, exception handlers, and server access logs.
Anyone with access to such logs may recover the complete API credential. The credential is also retained in the local
urlvariable, increasing the possibility that diagnostic tooling or future exception logging could expose it.Attack Path
- A legitimate user invokes the weather-query script.
- The script constructs a URL containing
key=<API_KEY>. - A proxy, monitoring platform, debugging tool, API gateway, or upstream server records the requested URL.
- An attacker or unauthorized operator obtains access to the recorded URL.
- The attacker extracts the
keyquery parameter. - The attacker reuses the key to make QWeather API requests until the credential is revoked or restricted.
Impact Assessment
Successful exploitation grants the attacker the API privileges assigned to the exposed QWeather key. This may allow unauthorized weather API requests, quota exhaustion, service disruption, and unexpected charges. It does not directly grant local operating-system privileges or arbitrary code execution.
- Remediation
View remediation
Remediation Suggestions
- Use the authentication-header mechanism supported by QWeather instead of placing the key in the query string.
- Construct requests with a dedicated authentication header and place only non-sensitive values in
params. - Ensure application, proxy, and monitoring logs redact authentication headers and sensitive query parameters.
- Avoid including complete request URLs in errors or debug output.
- Restrict the API key by service, source address, hostname, quota, or other controls offered by the provider.
- Rotate the current key if URLs containing it may already have been logged.
