T09 · Insecure Skill Coding Practices
- Location
scripts/managed_agents.py:27- Finding
API credentials can be transmitted to an attacker-controlled or plaintext endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/managed_agents.py:27,scripts/managed_agents.py:178-193,scripts/managed_agents.py:207-231,scripts/managed_agents.py:342-351,scripts/managed_agents.py:408-417, andscripts/managed_agents.py:877-886
Vulnerability Type: Arbitrary credential destination and insufficient transport validation
Risk Level: HighVulnerable Code
python API_BASE_URL = os.environ.get("ANTHROPIC_API_BASE_URL", "https://api.anthropic.com")python class ManagedAgentsClient: def __init__(self, *, backend: str = "auto", api_key_env: str = "ANTHROPIC_API_KEY", timeout: float = DEFAULT_TIMEOUT): self.api_key_env = api_key_env self.timeout = timeout self.api_key = os.environ.get(api_key_env) if not self.api_key: raise CliError(f"{api_key_env} is not set") if backend == "auto": backend = "sdk" if Anthropic is not None else "http" if backend not in {"sdk", "http"}: raise CliError(f"unsupported backend: {backend}") if backend == "sdk" and Anthropic is None: raise CliError("anthropic Python SDK is not installed; use --backend http or install `anthropic`") self.backend = backend self.sdk = Anthropic(api_key=self.api_key, timeout=timeout) if backend == "sdk" else Nonepython def _request( self, method: str, path: str, *, query: Optional[dict[str, Any]] = None, payload: Optional[dict[str, Any]] = None, raw_data: Optional[bytes] = None, content_type: Optional[str] = None, accept: str = "application/json", betas: Optional[list[str]] = None, ) -> Any: url = f"{API_BASE_URL.rstrip('/')}{path}" if query: encoded = urllib.parse.urlencode({k: v for k, v in query.items() if v is not None}, doseq=Tru ...[truncated 5510 chars]- Remediation
View remediation
Remediation Suggestions
- Parse the base URL with
urllib.parse.urlsplitbefore initializing either backend. - Require the
httpsscheme for every authenticated production request. - Allow
api.anthropic.comby default and reject other hosts unless the operator provides an explicit custom-gateway opt-in. - If custom gateways are supported, require a separate hostname allowlist and document that API credentials will be disclosed to the gateway.
- Reject URLs containing user information, fragments, unexpected ports, malformed hostnames, or ambiguous encoded components.
- Disable automatic redirects or validate every redirect target before forwarding authentication headers. Never forward
x-api-keyacross origins. - Centralize validated URL construction so
_request,download_file, andstream_eventscannot bypass the policy. - Apply equivalent base-URL restrictions when constructing the Anthropic SDK client.
- Make validation mandatory at client initialization rather than an advisory
doctorreport. - Add tests proving that plaintext URLs, unapproved hosts, embedded credentials, and cross-origin redirects cannot receive the API key.
- Parse the base URL with
