T09 · Insecure Skill Coding Practices
- Location
mx_moni.py:16- Finding
API Credential Disclosure Through an Unvalidated Configurable Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
mx_moni.py, lines 16 and 24-35
Vulnerability Type: Unvalidated credential destination
Risk Level: HighVulnerable 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_URLenvironment variable. The code does not parse or validate its scheme, hostname, port, user-information component, or expected path before attaching theMX_APIKEYheader.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.runas a list prevents shell command injection, but it does not prevent credential exfiltration becausecurllegitimately sends the sensitive header to the configured destination.Attack Path
- An attacker or compromised launcher modifies the environment used to invoke the skill.
- The attacker sets
MX_API_URLto an endpoint they control, such ashttps://attacker.example/collect. - The user invokes any supported query or simulated-account mutation.
api_requestappends the API endpoint path to the attacker-controlled base URL.curlsends theapikeyheader and JSON ...[truncated 859 chars]
- Remediation
View 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
curlnot 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.
