T09 · Insecure Skill Coding Practices
- Location
scripts/moltbook_digest.py:2229- Finding
Bypassable API Origin Validation Can Disclose the Moltbook Bearer Token
- Content
View full analysis
dict[str, Any]: query = urlencode({k: v for k, v in (params or {}).items() if v is not None}) url = f"{base_url}{path}" if query: url = f"{url}?{query}" headers = {"Accept": "application/json"} if api_key: headers["Authorization"] = f"Bearer {api_key}" transient_http_codes = {408, 425, 429, 500, 502, 503, 504} backoff_seconds = 0.8 for attempt in range(retries + 1): request = Request(url, headers=headers, method="GET") try: with urlopen(request, timeout=timeout) as response: return json.loads(response.read().decode("utf-8")) ``` ```python if not args.base_url.startswith("https://www.moltbook.com"): raise SystemExit("--base-url must point at https://www.moltbook.com") ``` ### Technical Analysis The code uses a string-prefix comparison to determine whether an API destination belongs to Moltbook. A prefix is not an origin or hostname validation mechanism. For example, the following attacker-controlled URL passes the check: ```text https://www.moltbook.com.attacker.example/api/v1 ``` Its actual hostname is `www.moltbook.com.attacker.example`, not `www.moltbook.com`. Because `api_get()` unconditionally attaches the configured Moltbook API key as an ` ...[truncated 1837 chars]- Remediation
View remediation
