T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/youtube_client.py:45
- Finding
- Cross-Origin Redirects May Disclose the API Bearer Token<![CDATA[ ## Vulnerability Details **File Location**: `scripts/youtube_client.py`, lines 45–61 **Vulnerability Type**: Authorization header exposure through unrestricted HTTP redirects **Risk Level**: Medium ### Vulnerable Code ```python headers = { "Authorization": f"Bearer {self.api_key}", "Content-Type": "application/json", "User-Agent": "OpenClaw-YouTube/1.0", "Accept": "application/json" } request_data = None if data: request_data = json.dumps(data).encode("utf-8") if method == "POST" and request_data is None: request_data = b"{}" req = urllib.request.Request(url, data=request_data, headers=headers, method=method) try: with urllib.request.urlopen(req, timeout=60) as response: ``` ### Technical Analysis The client places the `AISA_API_KEY` credential in the HTTP `Authorization` header and sends the request through `urllib.request.urlopen`. The default `urllib` opener automatically processes HTTP redirects, but the client does not validate that a redirect remains on the original `https://api.aisa.one` origin. Authorization headers associated with a redirected request may be propagated by the redirect handling path. Consequently, a cross-origin redirect could cause the bearer token to be sent to a server outside the intended AIsa API trust boundary. Sending the bearer token to the documented AIsa API is necessary for the Skill's declared YouTube search functionality. Allowing that credential to accompany an unrestricted cross-origin redirect is not necessary and exceeds the minimum network privilege required. Exploitation depends on the legitimate API endpoint, its infrastructure, or its DNS/routing path returning an attacker-controlled redirect. No evidence was found that the project itself deliberately redirects credentials or communicates with an undeclared destination. ### Attack Path 1. A user configures `AISA_API_KEY` and invokes one of the documented search commands. 2. The client creates a request to `https://ap ...[truncated 1122 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions Implement an explicit redirect policy rather than relying on the default `urllib` behavior: 1. Permit redirects only when the destination uses HTTPS. 2. Require the destination hostname to remain exactly `api.aisa.one`. 3. Reject redirects containing unexpected credentials, ports, or hostname variations. 4. Strip the `Authorization` header before following any cross-origin redirect. 5. Set a small maximum redirect count to prevent redirect loops. 6. Log rejected redirects without logging the bearer token. 7. Rotate the API key if credential exposure is suspected. A strict redirect handler can reject all automatic redirects: ```python class NoRedirectHandler(urllib.request.HTTPRedirectHandler): def redirect_request(self, req, fp, code, msg, headers, newurl): raise urllib.error.HTTPError( req.full_url, code, "Redirects are not permitted for authenticated API requests", headers, fp, ) opener = urllib.request.build_opener(NoRedirectHandler()) with opener.open(req, timeout=60) as response: return json.loads(response.read().decode("utf-8")) ``` If redirects are operationally required, parse each redirect destination with `urllib.parse.urlparse`, verify that its scheme is `https` and hostname is exactly `api.aisa.one`, and construct a fresh request. Never copy the `Authorization` header to a destination that fails the same-origin check. ]]>
