T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/tukeli.py:93
- Finding
- API credential may be disclosed through cross-origin HTTP redirects<![CDATA[ ## Vulnerability Details **File Location**: `scripts/tukeli.py:93-99`, `scripts/tukeli.py:124`, and `scripts/tukeli.py:145-147` **Vulnerability Type**: Credential exposure through unrestricted redirects **Risk Level**: Medium ### Vulnerable Code ```python resp = requests.post( url, params=url_params, files=files, headers=headers, timeout=timeout, ) ``` ```python resp = requests.get(url, params=all_params, headers=headers, timeout=timeout) ``` ```python if method == "POST": resp = requests.post(url, json=body, headers=headers, timeout=timeout) else: resp = requests.get(url, params=body, headers=headers, timeout=timeout) ``` The transmitted headers include the user's credential: ```python headers = { "APIKEY": api_key, "User-Agent": USER_AGENT, } ``` ### Technical Analysis Python Requests follows HTTP redirects by default for these calls. The credential is carried in the custom `APIKEY` header rather than the standard `Authorization` header. Redirect protections that specifically remove `Authorization` during a cross-origin redirect do not necessarily protect arbitrary credential headers. The initial destination is hardcoded to `https://picupapi.tukeli.net`, which limits ordinary endpoint manipulation. However, if that service, its DNS resolution, its TLS termination infrastructure, or its redirect behavior is compromised or misconfigured, it could return a redirect to another origin. The client does not reject redirects or verify that every redirect destination remains on the expected HTTPS host. Sending images and the API key to Tukeli is necessary for the declared remote image-processing functionality. Allowing the credential and image request to follow an unrestricted redirect exceeds the minimum network privilege required. ### Attack Path 1. An attacker compromises or misconfigures the Tukeli API endpoint, reverse proxy, or redirect behavior. 2. A user invokes image matting, face enhancement, AI backgr ...[truncated 974 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions Disable automatic redirects on all authenticated requests: ```python resp = requests.post( url, params=url_params, files=files, headers=headers, timeout=timeout, allow_redirects=False, ) ``` Apply the same control to every authenticated `requests.get` and `requests.post` call. If redirects are required: 1. Handle each redirect manually. 2. Parse and normalize the destination URL. 3. Require the scheme to be exactly `https`. 4. Require the normalized hostname to be exactly `picupapi.tukeli.net`. 5. Reject URLs containing unexpected ports, embedded credentials, or ambiguous host syntax. 6. Set a small maximum redirect count. 7. Reconstruct sensitive headers only after validating the next destination. 8. Consider using a dedicated `requests.Session` with a redirect policy that strips `APIKEY` whenever the origin changes. ]]>
