T09 · Insecure Skill Coding Practices
- Location
scripts/search_client.py:40- Finding
Bearer API Key May Be Forwarded Across HTTP Redirects
- Content
View full analysis
Vulnerability Details
File Location:
scripts/search_client.py, lines 40–59
Vulnerability Type: Authenticated request follows redirects without validating the destination origin
Risk Level: Mediumpython def aisa_post(api_key: str, path: str, body: dict[str, Any]) -> dict[str, Any]: url = f"{AISA_BASE}{path}" data = json.dumps(body).encode() req = urllib.request.Request( url, data=data, headers={ "Authorization": f"Bearer {api_key}", "Content-Type": "application/json", "Accept": "application/json", }, method="POST", ) try: with urllib.request.urlopen(req, timeout=60) as resp: return json.loads(resp.read().decode()) except urllib.error.HTTPError as e: body_text = e.read().decode() if e.fp else "" print(f"API error {e.code} on {path}: {body_text}", file=sys.stderr) return {"error": str(e), "status": e.code}Technical Analysis
The client creates an HTTP request containing the
AISA_API_KEYin anAuthorization: Bearerheader and submits it throughurllib.request.urlopen(). Python's standard URL opener follows supported HTTP redirects by default. The code does not disable redirects or validate that a redirect remains on the original HTTPS origin,api.aisa.one.Under redirect behavior where request headers are retained, an API response that redirects the request to another origin can cause the bearer credential to be transmitted to that destination. The implementation also has no explicit protection against an HTTPS-to-HTTP downgrade.
The initial use of HTTPS is appropriate, and transmitting the API key to AISA is necessary for the declared remote-search functionality. The flaw is the absence of a least-privilege boundary governing where that credential may be sent after the initial request.
Exploitation requires control or compromise of the authenticated API endpoint or other trusted i ...[truncated 1354 chars]
- Remediation
View remediation
Remediation Suggestions
- Disable automatic redirects for bearer-authenticated requests and handle redirect responses explicitly.
- If redirects are operationally required, resolve each destination and permit it only when:
- The URL scheme is
https. - The normalized hostname is exactly
api.aisa.one. - The destination port is the expected HTTPS port.
- User information and ambiguous hostname encodings are absent.
- The URL scheme is
- Strip the
Authorizationheader before following any cross-origin redirect. Do not restore it unless the destination passes an explicit same-origin allowlist check. - Reject HTTPS-to-HTTP redirects unconditionally.
- Apply a small redirect limit to prevent loops and unexpected request chains.
- Add automated tests covering same-origin redirects, cross-origin redirects, subdomain confusion, alternate ports, and HTTPS downgrade attempts.
- Document that search queries, extraction URLs, retrieved results, and the API credential are transmitted to AISA as part of the Skill's remote-search operation.
- Rotate the API key if logs or runtime evidence indicate that an unexpected redirect may already have occurred.
