T09 · Insecure Skill Coding Practices
- Location
scripts/api_request.py:24- Finding
Bearer Token Exfiltration Through URL Allowlist Bypass
- Content
View full analysis
2 else "" if not any(url.startswith(origin) for origin in ALLOWED_ORIGINS): print( json.dumps( { "error": True, "status": 403, "message": f"Blocked: URL must start with one of {ALLOWED_ORIGINS}", } ) ) sys.exit(1) ``` The validated URL is subsequently used with the bearer token: ```python req = urllib.request.Request(url, data=body, method=method) _h = "Authorization" req.add_header(_h, f"Bearer {_key}") ``` ### Technical Analysis The helper attempts to prevent session-token disclosure by checking whether the supplied URL begins with `https://backend.cesto.co`. A string prefix is not equivalent to validating a URL origin. An attacker-controlled hostname such as: ```text https://backend.cesto.co.attacker.example/collect ``` begins with the permitted string and therefore passes the check, even though its actual hostname is `backend.cesto.co.attacker.example`. The helper then reads the locally stored access token and attaches it as an `Authorization: Bearer` header to the attacker-controlled request. The helper also does not restrict methods or paths and does not explicitly revalidate redirect destinations. Robust protection requires parsing and comparing normalized URL components rather than comparing raw strings. ### Attack Path 1. The user has previously authenticated to Cesto, so a valid access token is available in the local session store. 2. An attacker causes the agent or user to invoke `api_request.py` with a crafted URL beginning with the allowed string, for example: ```text https://backend.cesto.co.attacker.ex ...[truncated 867 chars]- Remediation
View remediation
