T09 · Insecure Skill Coding Practices
- Location
scripts/gold_shgold_query.py:22- Finding
Unrestricted API Endpoint Override Can Disclose the AppKey
- Content
View full analysis
Vulnerability Details
File Location:
scripts/gold_shgold_query.py, lines 22 and 109–111
Vulnerability Type: Unvalidated destination override and credential disclosure
Risk Level: MediumVulnerable Code
python API_BASE_URL = os.environ.get("JIKE_API_BASE_URL", "https://api.jikeapi.cn").rstrip("/")python url = f"{API_BASE_URL}{API_PATH}?{urllib.parse.urlencode({'date': date_value, 'appkey': appkey})}" try: with urllib.request.urlopen(url, timeout=15) as response:Technical Analysis
The script accepts an undocumented
JIKE_API_BASE_URLenvironment variable without validating its scheme, hostname, port, or ownership. It concatenates that value with the API path and transmits the AppKey as a URL query parameter.An inherited or attacker-controlled environment can therefore redirect requests from the declared
https://api.jikeapi.cnservice to an arbitrary destination. Because the script does not require HTTPS, the override may also use plaintext HTTP.The AppKey is included directly in the query string of the redirected request. Consequently, a server controlling the selected endpoint can collect the credential. Query-string credentials may also be retained in HTTP server, proxy, monitoring, or diagnostic logs.
Attack Path
- An attacker gains the ability to influence the environment used to launch the Skill, such as through a compromised wrapper, deployment configuration, or orchestration layer.
- The attacker sets
JIKE_API_BASE_URLto an attacker-controlled HTTP or HTTPS origin. - A user or Agent invokes the script for a normal historical market-data query.
- The script loads the legitimate AppKey from
--key,JIKE_GOLD_SHGOLD_QUERY_KEY,JIKE_APPKEY, or the local.envfile. - The script constructs a request to the attacker-selected origin with
appkey=<secret>in its query string. - The attacker records the AppKey and may return manipulated JSON market data to the caller.
Impact A
...[truncated 539 chars]
- Remediation
View remediation
Remediation Suggestions
-
Remove the
JIKE_API_BASE_URLoverride from production code and use the fixed declared endpoint:python API_BASE_URL = "https://api.jikeapi.cn" -
If endpoint configurability is required for testing, parse and validate it before use:
- Require the
httpsscheme. - Permit only explicitly allowlisted hostnames.
- Reject embedded usernames or passwords.
- Reject unexpected ports, fragments, and malformed URLs.
- Keep test-only endpoint overrides disabled in production builds.
- Require the
-
Prefer sending the AppKey in an authorization header rather than a query parameter if the service supports it. This reduces exposure through URL logging and monitoring systems.
-
Avoid accepting secrets through
--key, because command-line arguments may be exposed through process listings, shell history, or execution telemetry. Prefer a protected environment variable or a dedicated secret-management facility. -
Ensure
.envfiles containing credentials have restrictive filesystem permissions and are excluded from source control. -
Add automated tests confirming that non-HTTPS URLs and unapproved hosts are rejected before any credential-bearing request is made.
-
