T09 · Insecure Skill Coding Practices
Error
- Location
- mx_moni.py:16
- Finding
- API Credential Disclosure Through an Unvalidated Configurable Endpoint## Vulnerability Details **File Location**: `mx_moni.py`, lines 16 and 24-35 **Vulnerability Type**: Unvalidated credential destination **Risk Level**: High ### Vulnerable Code ```python MX_API_URL = os.environ.get('MX_API_URL', 'https://mkapi2.dfcfs.com/finskillshub') def api_request(endpoint, payload): """Send an API request to the MX server.""" url = f"{MX_API_URL}{endpoint}" cmd = [ 'curl', '-s', '-X', 'POST', url, '-H', f'apikey: {MX_APIKEY}', '-H', 'Content-Type: application/json; charset=UTF-8', '-d', json.dumps(payload) ] try: result = subprocess.run(cmd, capture_output=True, text=True, timeout=30) ``` ### Technical Analysis The destination of authenticated API requests is controlled entirely by the `MX_API_URL` environment variable. The code does not parse or validate its scheme, hostname, port, user-information component, or expected path before attaching the `MX_APIKEY` header. Consequently, a process that can influence the script's environment can redirect requests to an attacker-controlled server. The script will then disclose both the API key and the request payload. It also permits an `http://` URL, under which the credential and portfolio operation data would be transmitted without transport encryption. Passing the arguments to `subprocess.run` as a list prevents shell command injection, but it does not prevent credential exfiltration because `curl` legitimately sends the sensitive header to the configured destination. ### Attack Path 1. An attacker or compromised launcher modifies the environment used to invoke the skill. 2. The attacker sets `MX_API_URL` to an endpoint they control, such as `https://attacker.example/collect`. 3. The user invokes any supported query or simulated-account mutation. 4. `api_request` appends the API endpoint path to the attacker-controlled base URL. 5. `curl` sends the `apikey` header and JSON ...[truncated 859 chars]
- Remediation
- ## Remediation Suggestions - Prefer a fixed production API origin rather than allowing arbitrary runtime overrides. - If configurability is required, parse the URL and enforce an explicit allowlist of approved HTTPS hostnames and ports. - Reject non-HTTPS schemes, embedded user information, fragments, unexpected ports, IP-literal substitutions, and malformed URLs. - Construct request paths relative to a validated origin rather than concatenating untrusted strings. - Ensure credentials are attached only after the final destination has passed validation. - Continue avoiding shell invocation, and configure `curl` not to follow redirects to unapproved origins. - Document development endpoint overrides separately and use distinct, least-privileged development credentials. - Rotate the API key if there is evidence that the script has run with an untrusted endpoint.
