T09 · Insecure Skill Coding Practices
Error
- Location
- lib/moltpho.py:586
- Finding
- Unvalidated API Base URL Can Redirect Bearer Credentials and Sensitive Data<![CDATA[ ## Vulnerability Details **File Location**: `lib/moltpho.py:143-144` and `lib/moltpho.py:586-598` **Vulnerability Type**: Unvalidated credential destination / sensitive-data exfiltration **Risk Level**: High ### Vulnerable Code ```python @classmethod def from_dict(cls, data: dict) -> Credentials: return cls( agent_id=data["agent_id"], api_key_id=data["api_key_id"], api_key_secret=data["api_key_secret"], api_base_url=data.get("api_base_url", API_BASE_URL), wallet_address=data["wallet_address"], ) ``` ```python base_url = creds.api_base_url if creds else API_BASE_URL url = f"{base_url}{endpoint}" request_headers = {"Content-Type": "application/json"} if creds: request_headers.update(_get_auth_headers(creds)) if headers: request_headers.update(headers) session = _create_session() response = session.request( method=method, url=url, params=params, json=data, headers=request_headers, timeout=timeout, ) ``` The authentication headers contain the API secret: ```python return { "Authorization": f"Bearer {creds.api_key_secret}", "X-Moltpho-Key-Id": creds.api_key_id, "Content-Type": "application/json", } ``` ### Technical Analysis The API destination is read directly from the local credentials JSON and used without validating its scheme or origin. Authenticated requests then attach the bearer secret and API key ID to that destination. Although newly registered credentials use the intended constant `https://api.moltpho.com`, subsequently loaded credentials may contain any `api_base_url`. The HTTP session also mounts an adapter for both HTTP and HTTPS, so a modified credential file can select an unencrypted HTTP endpoint. The configurable base URL is not required for the declared production shopping functionality and exceeds the minimum trust necessary for credential use. It turns a local configuration field into a credential-exfiltration sink. ### Attack Path ...[truncated 1355 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Do not deserialize the production API origin from the credentials file. Use the fixed `API_BASE_URL` constant for all authenticated requests. - If alternate environments are necessary, maintain an explicit allowlist of exact origins and require a separate, trusted deployment configuration. - Require HTTPS and reject HTTP, user-information components, fragments, unexpected ports, and non-allowlisted hosts. - Disable automatic redirects for authenticated requests or ensure authorization headers are never forwarded when the origin changes. - Validate the complete credentials schema before use. - Consider separating credentials by environment so production credentials cannot be sent to staging or development hosts. - Add tests proving that modified `api_base_url` values, cross-origin redirects, and HTTP destinations are rejected before any request is sent. ]]>
