T09 · Insecure Skill Coding Practices
- Location
scripts/crypto_utils.py:111- Finding
Arbitrary HTTPS API override can disclose bearer tokens to an attacker-controlled host
- Content
View full analysis
str: """Resolve the API base URL, enforcing HTTPS. Reads AGENT_ID_API environment variable. Rejects non-HTTPS URLs with a clear error message to prevent TLS downgrade attacks. """ url = os.environ.get("AGENT_ID_API", default).rstrip("/") if not url.startswith("https://"): print( f"Error: AGENT_ID_API must use https:// (got {url!r}). " "HTTP connections expose credentials in transit.", file=sys.stderr, ) sys.exit(1) return url ``` The resulting value is used with a bearer token in `scripts/rotate_keys.py:125-153`: ```python if args.apply: token = args.token or os.environ.get("AGENT_ID_TOKEN") if not token: print("Error: --apply requires --token or AGENT_ID_TOKEN.", file=sys.stderr) sys.exit(1) # ... response = requests.post( f"{API_BASE}/agents/{agent_id}/keys/rotate", headers={ "Authorization": f"Bearer {token}", "Content-Type": "application/json", }, json=payload, timeout=10, ) ``` ### Technical Analysis The API resolver only verifies that the configured URL begins with `https://`. It does not restrict the hostname to `agent-id.io` or another explicit trust allowlist. HTTPS protects a connection from passive interception, but it does not make an arbitrary recipient trustworthy. Because `API_BASE` is initialized from the `AGENT_ID_API` environment variable, an attacker who can influence the process environment can redirect authenticated requests to an attacker-controlled HTTPS server. The rotation flow then places the agent JWT in the HTTP `Authorization` hea ...[truncated 1569 chars]- Remediation
View remediation
