T09 · Insecure Skill Coding Practices
- Location
scripts/_auth.py:11- Finding
Application Credentials Can Be Sent to an Unrestricted API Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/_auth.py, lines 11 and 63-72
Vulnerability Type: Unvalidated credential transmission endpoint
Risk Level: HighVulnerable Code
python API_BASE = os.environ.get("CHANJING_API_BASE", "https://open-api.chanjing.cc")python def _request_new_token(app_id, secret_key): url = API_BASE + "/open/v1/access_token" req = urllib.request.Request( url, data=json.dumps({"app_id": app_id, "secret_key": secret_key}).encode("utf-8"), headers={"Content-Type": "application/json"}, method="POST", ) with urllib.request.urlopen(req, timeout=30) as resp: return json.loads(resp.read().decode("utf-8"))Technical Analysis
The
CHANJING_API_BASEenvironment variable is accepted as the authentication endpoint without validating its scheme, hostname, port, or origin._request_new_token()subsequently transmits the long-livedapp_idandsecret_keyto this endpoint.Sending these credentials to the official Chanjing token endpoint is necessary for the declared functionality. However, allowing the destination to be changed arbitrarily is not required for ordinary production use and violates least-exposure principles for secrets.
Both attacker-controlled HTTPS endpoints and unencrypted HTTP endpoints are accepted. An HTTP endpoint exposes credentials to network interception, while an attacker-controlled endpoint directly receives them. This issue requires an attacker or unsafe deployment configuration to influence the process environment.
Attack Path
- An attacker, malicious wrapper script, compromised launcher, or unsafe deployment manifest sets
CHANJING_API_BASEto an attacker-controlled URL. - The user invokes a workflow that calls
get_token()while no valid cached token exists. _request_new_token()appends/open/v1/access_tokento the attacker-selected base URL.- Th ...[truncated 856 chars]
- An attacker, malicious wrapper script, compromised launcher, or unsafe deployment manifest sets
- Remediation
View remediation
Remediation Suggestions
- Remove
CHANJING_API_BASEconfigurability in production and use the fixed official endpoint:python API_BASE = "https://open-api.chanjing.cc" - If endpoint customization is necessary for testing, parse the URL with
urllib.parse.urlparseand enforce:- HTTPS only.
- An explicit hostname allowlist.
- No embedded username or password.
- No unexpected port.
- No query string or fragment.
- Separate production and test configurations so production credentials cannot be used with development endpoints.
- Require explicit user confirmation before sending credentials to any non-default endpoint.
- Prevent HTTPS-to-HTTP redirect downgrade and validate the final response origin.
- Document that environment variables affecting credential destinations must be treated as security-sensitive configuration.
- Rotate the Chanjing credentials if the script has previously run with an untrusted
CHANJING_API_BASE.
- Remove
