T09 · Insecure Skill Coding Practices
- Location
scripts/common.py:179- Finding
Unrestricted API Base Can Expose Bearer Tokens and Identity Proofs to an Attacker-Controlled Server
- Content
View full analysis
None: parser.add_argument("--api-base", default=os.environ.get("CRUSTACEAN_API_BASE", DEFAULT_API_BASE)) parser.add_argument( "--identity-path", default=os.environ.get("OPENCLAW_IDENTITY_PATH", DEFAULT_IDENTITY_PATH), ) parser.add_argument( "--token-path", default=os.environ.get("CRUSTACEAN_TOKEN_PATH", DEFAULT_TOKEN_PATH), ) ``` ```python def api_request( method: str, api_base: str, endpoint: str, *, payload: dict[str, Any] | None = None, token: str | None = None, ) -> dict[str, Any]: base = api_base.rstrip("/") path = endpoint if endpoint.startswith("/") else f"/{endpoint}" url = f"{base}{path}" data = None headers = {"Accept": "application/json"} if payload is not None: data = json.dumps(payload).encode("utf-8") headers["Content-Type"] = "application/json" if token: headers["Authorization"] = f"Bearer {token}" req = urllib.request.Request(url, data=data, method=method.upper(), headers=headers) try: with urllib.request.urlopen(req, timeout=30) as resp: raw_body = resp.read().decode("utf-8") body = json.loads(raw_body) if raw_body else {} return { "status": resp.status, "ok": 200 <= resp.status < 300, "body": body, } except urllib.error.HTTPError as exc: raw_body = exc.read().decode("utf-8", errors="replace") try: body = json.loads(raw_body) if raw_body else {} except json.JSONDecodeError: body = {"ok": False, "error": {"code": "http_error", "message": ...[truncated 3520 chars]- Remediation
View remediation
