T09 · Insecure Skill Coding Practices
- Location
scripts/skill_router.py:49- Finding
API Key Disclosure Through Unvalidated Cross-Origin Redirects
- Content
View full analysis
Vulnerability Details
File Location:
scripts/skill_router.py, lines 49-67
Vulnerability Type: Outbound request redirect validation bypass and credential exposure
Risk Level: MediumVulnerable Code
python # Restrict outbound requests to the expected Media.io API host. parsed = urlparse(url) if parsed.scheme != 'https' or parsed.netloc.lower() != 'openapi.media.io': return {'error': f"Blocked endpoint host: {parsed.netloc}"} headers = { 'X-API-KEY': resolved_api_key, 'Content-Type': 'application/json' } # Replace path parameters in endpoint URLs. if '{' in url: for k, v in params.items(): url = url.replace(f'{{{k}}}', str(v)) # Keep non-path parameters in the JSON body. body = {k: v for k, v in params.items() if f'{{{k}}}' not in api['endpoint']} try: resp = requests.request(method, url, headers=headers, json={'data': body} if body else {}, timeout=30)Technical Analysis
The implementation verifies that the initial endpoint uses HTTPS and has the exact hostname
openapi.media.io. It then sends the request usingrequests.requestwithout disabling redirects.The Python
requestslibrary follows redirects by default. The code does not inspect or validate redirect destinations before following them. Althoughrequestshas special handling for standard authorization headers, the credential is supplied through the customX-API-KEYheader. Such custom headers can remain attached to a redirected request, including a redirect to a different origin.Consequently, the initial host allowlist does not guarantee that the API key is sent exclusively to
openapi.media.io. A cross-origin redirect returned by the accepted endpoint could cause the request and its sensitive header to be delivered to another host.Exploitation depends on the trusted endpoint returning an attacker-controlled cross-origin redirect, such as through server compromise, an upstre ...[truncated 1444 chars]
- Remediation
View remediation
Remediation Suggestions
Disable automatic redirects for authenticated API requests:
python resp = requests.request( method, url, headers=headers, json={'data': body} if body else {}, timeout=30, allow_redirects=False, )Treat unexpected redirect responses as errors. If redirects are operationally required, implement controlled redirect handling:
- Follow redirects manually.
- Parse and normalize every redirect destination.
- Require the destination scheme to remain
https. - Require the destination hostname to remain exactly
openapi.media.io. - Reject user-information components, nonstandard ports, malformed hosts, and protocol-relative destinations.
- Set a small maximum redirect count to prevent loops.
- Remove
X-API-KEYbefore any request whose origin differs from the original origin. - Add automated tests covering
301,302,303,307, and308redirects to both approved and unapproved hosts.
A hardened implementation should also validate the fully substituted URL immediately before transmission so that the URL receiving the credential is always subject to the final allowlist check.
