T09 · Insecure Skill Coding Practices
Error
- Location
- src/a2a4b2b_mcp/client.py:7
- Finding
- API Key Disclosure Through Untrusted .env Configuration## Vulnerability Details **File Location**: `src/a2a4b2b_mcp/client.py:7-47` **Vulnerability Type**: Untrusted configuration loading and credential redirection **Risk Level**: High ### Vulnerable Code ```python def load_env(): """Load environment variables from a .env file.""" possible_paths = [ os.path.join(os.path.dirname(__file__), '.env'), os.path.join(os.path.dirname(__file__), '..', '..', '.env'), os.path.join(os.getcwd(), '.env'), ] for env_path in possible_paths: if os.path.exists(env_path): with open(env_path, 'r') as f: for line in f: line = line.strip() if line and not line.startswith('#') and '=' in line: key, value = line.split('=', 1) os.environ.setdefault(key, value) break load_env() class A2A4B2BClient: def __init__(self, api_key: Optional[str] = None, base_url: Optional[str] = None): self.api_key = api_key or os.getenv("A2A4B2B_API_KEY") self.base_url = base_url or os.getenv( "A2A4B2B_BASE_URL", "https://a2a4b2b.com" ) self.agent_id = os.getenv("A2A4B2B_AGENT_ID") if not self.api_key: raise ValueError("API Key is required. Set A2A4B2B_API_KEY env var.") def _headers(self) -> Dict[str, str]: return { "X-API-Key": self.api_key, "Content-Type": "application/json" } def _request(self, method: str, endpoint: str, **kwargs) -> Any: url = f"{self.base_url}{endpoint}" response = requests.request(method, url, headers=self._headers(), **kwargs) response.raise_for_status() return response.json() if response.content else None ``` ### Technical Analysis Importing the client module automatically searches for and loads a `.env` file. One of the se ...[truncated 1746 chars]
- Remediation
- ## Remediation Suggestions 1. Remove automatic `.env` discovery from the current working directory. 2. Require the host application to provide security-sensitive configuration explicitly. 3. If `.env` support is required, load only a single administrator-selected path with verified ownership and restrictive permissions. 4. Permit only HTTPS API destinations. 5. Validate the API origin against an explicit allowlist, defaulting to `https://a2a4b2b.com`. 6. Reject URLs containing user information, fragments, unexpected ports, or non-approved hosts. 7. Ensure credentials are not forwarded when an HTTP redirect changes the origin. 8. Consider removing configurable production endpoints entirely unless custom deployments are a documented requirement.
