T09 · Insecure Skill Coding Practices
- Location
scripts/youtube_client.py:50- Finding
Bearer API Key May Be Disclosed Through Cross-Origin HTTP Redirects
- Content
View full analysis
Vulnerability Details
File Location:
scripts/youtube_client.py, lines 50–69
Vulnerability Type: Bearer credential exposure through unrestricted redirects
Risk Level: Mediumpython headers = { "Authorization": f"Bearer {self.api_key}", "Content-Type": "application/json", "User-Agent": "AIsa-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
AISA_API_KEYin the HTTPAuthorizationheader and submits the request throughurllib.request.urlopen. The standard URL opener handles HTTP redirects automatically, while this implementation does not enforce a same-origin redirect policy or explicitly remove credentials when the destination origin changes.Consequently, a redirect returned by
api.aisa.onecould cause a follow-up request containing the bearer credential to be sent to another host. Exploitation requires influence over the API endpoint or its redirect behavior; ordinary untrusted search input cannot directly choose the destination becauseBASE_URLand the invoked endpoint are fixed.Transmission of the API key to the original HTTPS API is documented in
SKILL.mdand is necessary for the declared relay-based YouTube search functionality. The issue is therefore not the initial credential transmission, but the absence of a strict redirect boundary around that transmission.Attack Path
- A user invokes one of the documented search or competitor-research commands.
- The client reads
AISA_API_KEYand sends it tohttps://api.aisa.oneas a bearer token. - An attacker who has compromised or ...[truncated 965 chars]
- Remediation
View remediation
Remediation Suggestions
- Disable automatic redirects for authenticated requests and handle redirect responses explicitly.
- If redirects are operationally required, parse and normalize every redirect destination and permit it only when:
- the scheme remains
https; - the normalized hostname is exactly
api.aisa.one; - the effective port is the expected HTTPS port; and
- user-information and other ambiguous URL components are absent.
- the scheme remains
- Reject redirects to any other origin rather than forwarding the bearer token.
- Construct a fresh redirected request instead of reusing headers. Add
Authorizationonly after the destination passes the same-origin validation. - Set a conservative maximum redirect count to prevent redirect loops.
- Consider using a narrowly scoped and revocable API key. Rotate the key immediately if redirect-based disclosure is suspected.
- Add automated tests covering same-origin redirects, cross-origin redirects, HTTPS-to-HTTP downgrades, hostname normalization, and confirmation that credentials are absent from rejected or external requests.
