T09 · Insecure Skill Coding Practices
- Location
scripts/mx_stock_simulator.py:15- Finding
Configurable API endpoint permits API key exfiltration
- Content
View full analysis
Vulnerability Details
File Location:
scripts/mx_stock_simulator.py, lines 15–16 and 50–61
Vulnerability Type: Unrestricted credential-bearing network destination
Risk Level: HighVulnerable Code
python MX_APIKEY = os.environ.get('MX_APIKEY') MX_API_URL = os.environ.get('MX_API_URL', 'https://mkapi2.dfcfs.com/finskillshub')python def make_request(endpoint, payload): """Send a POST request to the API.""" url = f"{MX_API_URL}{endpoint}" headers = { 'apikey': MX_APIKEY, 'Content-Type': 'application/json' } try: response = requests.post(url, headers=headers, json=payload, timeout=30) response.raise_for_status() return response.json() except requests.exceptions.RequestException as e: print(f"Request failed: {str(e)}") return NoneTechnical Analysis
The simulated-trading client allows the request origin to be overridden through the
MX_API_URLenvironment variable. It does not validate the URL scheme, hostname, port, or effective destination before attaching theMX_APIKEYcredential.Consequently, a process or configuration source capable of influencing the script's environment can redirect every simulator request to an arbitrary server. The script will transmit the API key in the
apikeyheader along with operation payloads. The code also relies on the default redirect behavior ofrequests, without independently verifying the final response origin.This behavior exceeds the documented network privilege.
README.mdandSKILL.mdstate that data is sent only to the Eastmoney API domain, but the implementation permits any destination supplied through the environment.Attack Path
- An attacker influences a deployment manifest, shell profile, wrapper script, process environment, or copied setup command used to launch the Skill.
- The attacker sets
MX_API_URLto an HTTP ...[truncated 1009 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove the
MX_API_URLoverride if custom API origins are not required. - Otherwise, parse the configured URL and enforce an exact allowlist:
- Scheme must be
https. - Hostname must be exactly
mkapi2.dfcfs.com. - Port must be the expected HTTPS port.
- User-information components must be rejected.
- The normalized base path must be validated.
- Scheme must be
- Disable automatic redirects with
allow_redirects=False, or validate every redirect target before following it. - Attach
MX_APIKEYonly after destination validation succeeds. - Fail closed when the URL is malformed or outside the approved origin.
- Add tests covering HTTP URLs, lookalike domains, embedded credentials, alternate ports, subdomains, and cross-origin redirects.
- Update the documentation so that its network-security claims accurately match the implementation.
- Remove the
