T09 · Insecure Skill Coding Practices
- Location
scripts/chanjing_get_token.py:22- Finding
Environment-Controlled API Base URL Can Exfiltrate Chanjing Credentials
- Content
View full analysis
Vulnerability Details
File Location:
scripts/chanjing_get_token.py, lines 22–34, 67–76, and 110–111
Vulnerability Type: Unvalidated credential transmission endpoint
Risk Level: HighVulnerable Code
python def openapi_base_url() -> str: return ( os.environ.get("CHANJING_OPENAPI_BASE_URL") or os.environ.get("CHANJING_API_BASE") or _DEFAULT_OPENAPI_BASE ).rstrip("/") CONFIG_DIR = credentials_config_dir() CONFIG_FILE = CONFIG_DIR / "credentials.json" API_URL = openapi_base_url() + "/open/v1/access_token"python def fetch_token(app_id, secret_key): req = urllib.request.Request( API_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: body = json.loads(resp.read().decode("utf-8")) return bodypython try: resp = fetch_token(app_id, secret_key) except Exception as e: print(f"请求 Token 失败: {e}", file=sys.stderr) sys.exit(1)Technical Analysis
The token client reads
CHANJING_OPENAPI_BASE_URLor the legacyCHANJING_API_BASEdirectly from the process environment and uses the resulting value as the destination for a request containing bothapp_idandsecret_key.The implementation does not validate:
- That the URL uses HTTPS.
- That the destination hostname is
open-api.chanjing.cc. - That the port is expected.
- That the URL does not contain embedded user information.
- That redirects remain on the approved host.
Although
manifest.yamldocuments a network allowlist, the Python code does not enforce that allowlist itself. Security therefore depends on the runtime sandbox applying the manifest correctly. In an execution environment that does not enforce it, or where network policy ...[truncated 1508 chars]- Remediation
View remediation
Remediation Suggestions
- Remove production endpoint overrides unless custom deployments are an explicit requirement.
- Parse the URL with
urllib.parse.urlsplitand require:- Scheme exactly equal to
https. - Hostname exactly equal to
open-api.chanjing.cc, or a narrowly defined trusted-host allowlist. - No embedded username or password.
- Only an approved port, normally 443.
- Scheme exactly equal to
- Reject malformed URLs and values containing unexpected path, query, or fragment components.
- Disable redirects for the credential request or validate every redirect destination against the same HTTPS hostname allowlist.
- Treat manifest-level network restrictions as defense in depth rather than the only enforcement mechanism.
- If custom endpoints must remain supported, require explicit user approval and clearly warn that AK/SK will be transmitted to the configured host.
- Add automated tests proving that HTTP URLs, unapproved hosts, unusual ports, and cross-host redirects are rejected.
