T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/ima_runtime/shared/client.py:78
- Finding
- Primary API Credential Exposed in Upload-Token Query Parameters<![CDATA[ ## Vulnerability Details **File Location**: `scripts/ima_runtime/shared/client.py:78-96` **Vulnerability Type**: Credential exposure through URL query parameters **Risk Level**: High ### Vulnerable Code ```python url = f"{im_base_url}/api/rest/oss/getuploadtoken" params = { "appUid": api_key, "appId": APP_ID, "appKey": APP_KEY, "cmimToken": api_key, "sign": sign, "timestamp": ts, "nonce": nonce, "fService": "privite", "fType": "picture", "fSuffix": suffix, "fContentType": content_type, } logger.info(f"Getting upload token: suffix={suffix}") try: resp = requests.get(url, params=params, timeout=30) ``` ### Technical Analysis The upload-token request places the primary `IMA_API_KEY` in two GET query parameters: `appUid` and `cmimToken`. Although HTTPS protects the request while it is in transit, it does not prevent the complete URL from being retained by the destination server, reverse proxies, load balancers, network monitoring products, or exception diagnostics. Query parameters are unsuitable for long-lived authentication credentials because URLs are routinely treated as loggable metadata. Reusing the primary API credential for the upload service also gives the upload-token flow more authority than a narrowly scoped, short-lived upload credential would require. The upload operation is necessary for local media, but transmitting the primary credential in the URL exceeds a safe minimum-privilege design. ### Attack Path 1. The operator supplies a local media file or triggers upload of a derived video cover. 2. The runtime calls `get_upload_token()`. 3. The primary API key is serialized into the request URL as both `appUid` and `cmimToken`. 4. An HTTP access log, reverse-proxy log, monitoring system, or diagnostic record stores the complete URL. 5. A party with access to that record extracts the API key. 6. The exposed key can be replayed against APIs that accept the same credential. ### Impact Ass ...[truncated 436 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Replace the GET request with an authenticated POST request. 2. Transmit authentication through an `Authorization` header rather than query parameters. 3. Do not reuse the primary API key as both an account identifier and upload token. 4. Have the primary API issue a short-lived, upload-only credential with restricted object size, content type, destination, and expiration. 5. Ensure reverse proxies and application servers redact authentication fields. 6. Rotate API keys that may already have appeared in URL logs. 7. Add automated tests asserting that prepared request URLs never contain `IMA_API_KEY`, `appUid`, or `cmimToken` credential values. ]]>
