T09 · Insecure Skill Coding Practices
- Location
scripts/tenwhy_query.py:19- Finding
Undocumented API Endpoint Override Can Disclose the AppKey
- Content
View full analysis
Vulnerability Details
File Location:
scripts/tenwhy_query.py, lines 19 and 144
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_MAP[command]}?{urllib.parse.urlencode({**params, 'appkey': appkey})}"Technical Analysis
The undocumented
JIKE_API_BASE_URLenvironment variable controls the complete origin to which API requests are sent. The script does not validate that the configured URL uses HTTPS or that its hostname is the intendedapi.jikeapi.cnservice.The request URL includes the AppKey as an
appkeyquery parameter. Consequently, a process capable of influencing the execution environment can redirect the request to an attacker-controlled HTTP or HTTPS server and receive the credential. Query parameters may also be recorded in destination-server access logs, proxy logs, monitoring systems, and other URL-processing infrastructure.The same redirected request can disclose user-supplied keywords and pagination metadata. The behavior is not needed for the Skill's documented operation and is not disclosed in
SKILL.md.Attack Path
- An attacker or compromised launcher sets
JIKE_API_BASE_URLto an attacker-controlled endpoint, such ashttps://attacker.example. - A user or agent invokes the documented
queryorrandomcommand. load_appkey()obtains a valid AppKey from the command line, environment, or local.envfile.request_api()appends the AppKey and business parameters to the attacker-controlled base URL.urllib.request.urlopen()sends the request to the attacker's server.- The attacker extracts the AppKey and any keyword or pagination data from the request URL.
Impact Assessment
Successful exploitation exposes the Jike API credential and user query data. The attacker can ...[truncated 476 chars]
- An attacker or compromised launcher sets
- Remediation
View remediation
Remediation Suggestions
- Remove the
JIKE_API_BASE_URLoverride if custom API origins are not a documented requirement. - Otherwise, parse the URL and enforce an explicit allowlist:
- Require the
httpsscheme. - Require the exact hostname
api.jikeapi.cn. - Reject embedded user information, unexpected ports, fragments, and deceptive hostname suffixes.
- Require the
- Construct request URLs from a fixed trusted origin and fixed path map rather than concatenating an environment-controlled base URL.
- If the upstream API supports it, transmit the AppKey in an authorization header rather than the query string.
- Avoid accepting credentials through
--key, because command-line arguments may be visible in process listings and shell history; prefer a protected environment variable or restrictive credential file. - Ensure logs, exceptions, and diagnostics never print complete URLs containing credentials.
- Add tests confirming that non-HTTPS schemes, unapproved hosts, malformed URLs, and redirect attempts are rejected. Where practical, disable cross-origin redirects or verify the final redirect destination before forwarding credentials.
- Remove the
