T09 · Insecure Skill Coding Practices
- Location
scripts/search.py:63- Finding
API Key Disclosure Through Automatically Followed Cross-Origin Redirects
- Content
View full analysis
Vulnerability Details
File Location:
scripts/search.py, lines 63–72
Vulnerability Type: Credential disclosure through unsafe HTTP redirect handling
Risk Level: Mediumpython req = request.Request( url, data=json.dumps(body).encode('utf-8'), headers={ 'Content-Type': 'application/json', 'X-Api-Key': api_key }, method='POST' ) try: with request.urlopen(req) as response:Technical Analysis
The script attaches the
OCTEN_API_KEYcredential to a customX-Api-Keyrequest header and submits the request usingurllib.request.urlopen(). Although the initial URL is validated against the hardcodedhttps://api.octen.ai/searchendpoint,urlopen()uses redirect handling by default.Python's standard redirect handling can construct a redirected request using headers from the original request. Consequently, an HTTP redirect—particularly a
301,302, or303response—may cause the custom authentication header to be forwarded to a different origin. The initial endpoint validation is not repeated for the redirect destination.Sending the API key to the official service is necessary for the declared authenticated search functionality. The vulnerability is therefore not the intended transmission itself, but the failure to constrain subsequent redirect destinations and credential forwarding. This also makes the documentation claim that the key is only sent to the hardcoded endpoint stronger than the code actually guarantees.
Attack Path
- A user or agent invokes the Skill with a search query.
- The script reads
OCTEN_API_KEYfrom the environment. - It sends a request containing the key in the
X-Api-Keyheader to the allowlisted Octen endpoint. - If that endpoint, its infrastructure, or an upstream component is compromised or misconfigured, it returns a redirect to an attacker-controlled HTTPS URL.
- The standard URL opener follows th ...[truncated 933 chars]
- Remediation
View remediation
Remediation Suggestions
- Disable automatic redirects for requests carrying authentication credentials. Use a custom
urllib.request.HTTPRedirectHandlerthat rejects all redirects and treats any 3xx response as an error. - If redirects are operationally required, validate every redirect destination before following it. Require the exact HTTPS scheme, hostname, port, and approved path rather than relying on suffix or substring matching.
- Never forward
X-Api-Keyacross origins. Strip the authentication header before constructing any redirected request, including redirects that change scheme, hostname, or port. - Prefer rejecting redirects entirely for this fixed API endpoint because the Skill documentation states that the endpoint is immutable and allowlisted.
- Add automated tests using a local redirecting server to verify that cross-origin and same-origin redirects cannot receive the API key.
- Keep TLS certificate verification enabled and avoid adding permissive SSL contexts or hostname-verification bypasses.
- Update the security documentation only after redirect behavior is technically enforced, ensuring its guarantees accurately match runtime behavior.
- Disable automatic redirects for requests carrying authentication credentials. Use a custom
