T09 · Insecure Skill Coding Practices
- Location
- scripts/feishu_bitable.py:31
- Finding
- Unrestricted API host override enables credential, token, and Bitable data redirection## Vulnerability Details **File Location**: `scripts/feishu_bitable.py:31-37, 88-104, 108-126` **Vulnerability Type**: Arbitrary network destination for sensitive authentication material and Bitable data **Risk Level**: High ### Vulnerable Code ```python DEFAULT_HOST = os.getenv("FEISHU_API_HOST", "https://open.feishu.cn") DEFAULT_CACHE = os.getenv( "FEISHU_TOKEN_CACHE", str(Path.home() / ".cache" / "openclaw" / "feishu_tenant_token.json") ) TOKEN_URL = f"{DEFAULT_HOST}/open-apis/auth/v3/tenant_access_token/internal" ``` ```python def get_tenant_token() -> str: app_id = os.getenv("FEISHU_APP_ID") app_secret = os.getenv("FEISHU_APP_SECRET") if not app_id or not app_secret: raise RuntimeError("Missing env: FEISHU_APP_ID / FEISHU_APP_SECRET") cached = _load_cached_token(DEFAULT_CACHE) if cached: log_debug("Using cached token") return cached resp = _http_json("POST", TOKEN_URL, headers={}, body={"app_id": app_id, "app_secret": app_secret}) if resp.get("code") != 0: raise RuntimeError(f"Token error: {resp}") token = resp["tenant_access_token"] expire = resp.get("expire", 3600) _save_cached_token(DEFAULT_CACHE, token, expire) log_debug("Token refreshed") return token ``` ```python def _api_get(url: str) -> Dict[str, Any]: token = get_tenant_token() return _http_json("GET", url, headers={"Authorization": f"Bearer {token}"}) def _api_post(url: str, body: Dict[str, Any]) -> Dict[str, Any]: token = get_tenant_token() return _http_json("POST", url, headers={"Authorization": f"Bearer {token}"}, body=body) def _api_put(url: str, body: Dict[str, Any]) -> Dict[str, Any]: token = get_tenant_token() return _http_json("PUT", url, headers={"Authorization": f"Bearer {token}"}, body=body) def _api_delete(url: str) -> Dict[str, Any]: token = get_tenant_token() return ...[truncated 2869 chars]
- Remediation
- ## Remediation Suggestions 1. Remove `FEISHU_API_HOST` configurability if alternate endpoints are not strictly required. 2. If configurability is required, parse the value with a standard URL parser and require HTTPS. 3. Allowlist exact trusted Feishu API hostnames rather than relying on suffix matching. Reject user information, fragments, unexpected ports, raw IP addresses, and deceptive hostname suffixes. 4. Use independently validated, fixed origins for authentication and Bitable API traffic. 5. Prevent credentials and `Authorization` headers from being forwarded to a different origin during redirects. Prefer disabling redirects for authenticated requests or validating every redirect target. 6. Reject cleartext HTTP endpoints and fail closed when destination validation fails. 7. Document the accepted endpoint allowlist and treat any endpoint change as a security-sensitive configuration operation. 8. Apply minimum Feishu application scopes so that compromise of credentials does not grant unnecessary write or delete permissions.
