T09 · Insecure Skill Coding Practices
- Location
scripts/kagi_client.py:41- Finding
API Authorization Token May Be Forwarded Across Redirect Boundaries
- Content
View full analysis
Vulnerability Details
File Location:
scripts/kagi_client.py, lines 41–54
Vulnerability Type: Credential exposure through unsafe automatic redirect handling
Risk Level: MediumVulnerable Code
python headers = { "Authorization": f"Bot {_token()}", "Accept": "application/json", } data = None if json_body is not None: data = json.dumps(json_body).encode("utf-8") headers["Content-Type"] = "application/json" req = urllib.request.Request(url, method=method.upper(), headers=headers, data=data) try: with urllib.request.urlopen(req, timeout=timeout) as resp:Technical Analysis
The client adds the Kagi API token to the HTTP
Authorizationheader and invokesurllib.request.urlopen, which uses automatic redirect handling. The implementation does not reject redirects or validate the scheme and hostname of a redirect destination.Consequently, a redirect response could cause a credential-bearing request to cross the intended
https://kagi.comorigin boundary. An attacker must first be able to influence the authenticated endpoint's redirect response, such as through compromise of the remote service or another network condition capable of producing a trusted HTTPS response. Ordinary network interception without a valid TLS trust path is insufficient.Attack Path
- A user invokes
kagi_search.pyorkagi_fastgpt.py. _requestreadsKAGI_API_TOKENorKAGI_API_KEYand inserts it into theAuthorizationheader.- The authenticated Kagi endpoint returns an attacker-controlled redirect to another origin.
- The standard-library redirect handler follows the redirect without an application-level destination allowlist.
- If the authorization header is retained by the applicable Python runtime and redirect flow, the attacker-controlled destination receives the Kagi API token.
- The attacker reuses the token to make unauthorized Kagi API requests.
...[truncated 490 chars]
- A user invokes
- Remediation
View remediation
Remediation Suggestions
Disable automatic redirects for authenticated API requests and reject unexpected 3xx responses. If redirects are operationally required, implement a custom redirect handler that:
- Allows only HTTPS destinations.
- Compares normalized destination hostnames against an explicit allowlist, such as
kagi.com. - Removes
Authorization, cookies, and other sensitive headers before any cross-origin redirect. - Rejects HTTPS-to-HTTP downgrades.
- Limits the number of redirects to prevent redirect loops.
- Records a sanitized error without logging the token or complete sensitive response data.
Prefer treating every origin change as an authentication boundary. Construct a new request after validating an allowed redirect rather than automatically reusing the original request headers.
