T09 · Insecure Skill Coding Practices
- Location
- scripts/lib/client.py:59
- Finding
- Bearer Token May Be Disclosed Through Cross-Origin HTTP Redirects## Vulnerability Details **File Location**: `scripts/lib/client.py`, lines 59-82 **Vulnerability Type**: Authenticated request redirect without destination validation **Risk Level**: Medium ### Vulnerable Code ```python def _headers(self): return { "Authorization": f"Bearer {self.api_key}", "Content-Type": "application/json;charset=utf-8", "User-Agent": "OpenClaw-VisionOneTI/1.0", } def _request(self, method, path, params=None, body=None): url = f"{self.base_url}{path}" if params: # Filter out None values clean = {k: v for k, v in params.items() if v is not None} if clean: url += "?" + urlencode(clean) data = None if body is not None: data = json.dumps(body).encode("utf-8") req = urllib.request.Request( url, data=data, headers=self._headers(), method=method, ) last_err = None for attempt in range(MAX_RETRIES): try: with urllib.request.urlopen(req, timeout=60) as resp: ``` ### Technical Analysis The initial API destination is appropriately constrained through a fixed region-to-hostname mapping and HTTPS. Sending `VISION_ONE_API_KEY` as a Bearer token to the selected Trend Micro Vision One endpoint is necessary for the Skill’s declared functionality and does not, by itself, exceed minimum privilege requirements. The security issue arises because `urllib.request.urlopen()` uses automatic HTTP redirect handling. The code does not inspect redirect responses or validate the scheme, hostname, and port of the redirect destination. Request headers may be copied to the redirected request, including the `Authorization` header. Consequently, if an approved API endpoint returns a redirect to another origin, the client may forward the Vision One Bearer token to that destination. Exploitation requires control or compromise of the trusted A ...[truncated 1681 chars]
- Remediation
- ## Remediation Suggestions Replace unrestricted automatic redirect handling with an explicit redirect policy: 1. Disable automatic redirects or implement a custom `urllib.request.HTTPRedirectHandler`. 2. Parse every redirect destination with `urllib.parse.urlparse`. 3. Require the destination scheme to remain `https`. 4. Require the destination hostname to exactly match the hostname selected from the fixed `REGIONS` mapping. 5. Reject redirects to unapproved hosts, IP literals, nonstandard ports, embedded credentials, or downgraded HTTP destinations. 6. Remove the `Authorization` header whenever the origin changes, even if cross-origin redirects are permitted for another reason. 7. Set a small redirect limit and reject redirect loops. 8. Add tests covering same-origin redirects, cross-origin redirects, HTTPS-to-HTTP downgrades, hostname suffix tricks, and port changes. 9. Continue using separate least-privilege API keys: use a view-only token for read commands and a distinct configuration-capable token only when write functionality is required.
