T09 · Insecure Skill Coding Practices
- Location
scripts/mss_client.py:8- Finding
Unrestricted API endpoint permits API-key disclosure and transmission over insecure transport
- Content
View full analysis
Vulnerability Details
File Location:
scripts/mss_client.py:8-45; related configuration inscripts/setup_env.py:5-19
Vulnerability Type: Unvalidated destination for authenticated network requests
Risk Level: HighVulnerable Code
python def get_client(): env_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), ".env") load_dotenv(env_path) api_key = os.environ.get("MSS_API_KEY") endpoint = os.environ.get("MSS_API_ENDPOINT") if not api_key or not endpoint: print("ERROR: MSS not configured. Please provide your API key to initialize.") sys.exit(1) headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json", "Accept": "application/json", } return endpoint, headers def api_get(path, params=None): endpoint, headers = get_client() resp = requests.get(f"{endpoint}{path}", headers=headers, params=params, timeout=15) resp.raise_for_status() return resp.json() def api_post(path, payload): endpoint, headers = get_client() resp = requests.post(f"{endpoint}{path}", headers=headers, json=payload, timeout=15) resp.raise_for_status() return resp.json() def api_patch(path, payload): endpoint, headers = get_client() resp = requests.patch(f"{endpoint}{path}", headers=headers, json=payload, timeout=15) resp.raise_for_status() return resp.json()The endpoint is persisted without validation:
python def save_env(api_key, endpoint): env_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), ".env") lines = [] if os.path.exists(env_path): with open(env_path, "r") as f: for line in f: if not line.startswith("MSS_API_KEY=") and not line.startswith("MSS_API_ENDPOINT="): lines.append(line) lines.append(f"MSS_API_KEY={api_k ...[truncated 2690 chars]- Remediation
View remediation
Remediation Suggestions
- Require
https://and reject plaintext HTTP. - Validate the parsed hostname against an administrator-controlled allowlist of authorized MSS domains.
- Reject URLs containing user information, fragments, unexpected ports, loopback addresses, link-local addresses, and private destinations unless explicitly required by the deployment.
- Normalize the endpoint with
urllib.parseand construct paths safely rather than concatenating arbitrary strings. - Disable cross-origin redirects for authenticated calls, or verify that every redirect destination remains on the approved origin before forwarding the authorization header.
- Prefer deployment-managed endpoint configuration rather than accepting an endpoint through ordinary conversational input.
- Use narrowly scoped, short-lived API tokens and support immediate token revocation.
- Consider certificate pinning or a deployment-specific trust store for high-sensitivity environments.
- Clearly display the validated destination and require explicit confirmation before first transmitting a credential.
- Require
