T09 · Insecure Skill Coding Practices
- Location
- scripts/_utils.sh:5
- Finding
- Environment-Controlled API Base Can Redirect Credentials, Tokens, and Documents<![CDATA[ ## Vulnerability Details **File Location**: `scripts/_utils.sh:5`, `scripts/auth.sh:68-71`, `scripts/list-resources.sh:30-31`, `scripts/delete-head.sh:37-38 and 71-72`, `scripts/upload-document.sh:61-64` **Vulnerability Type**: Unvalidated security-sensitive endpoint override **Risk Level**: High ### Vulnerable Code ```bash # scripts/_utils.sh:5 API_BASE="${API_BASE:-https://platform-api.unith.ai}" ``` ```bash # scripts/auth.sh:68-71 unith_curl -X POST "$API_BASE/auth/token" \ -H 'Content-Type: application/json' \ -H 'accept: application/json' \ -d "$(jq -n --arg e "$UNITH_EMAIL" --arg k "$UNITH_SECRET_KEY" '{email:$e, secretkey:$k}')" ``` ```bash # scripts/list-resources.sh:30-32 if ! unith_curl -X GET "$API_BASE/headvisual/list" \ -H "$AUTH_HEADER" \ -H 'accept: application/json'; then ``` ```bash # scripts/delete-head.sh:37-39 if ! unith_curl -X GET "$API_BASE/head/$HEAD_ID" \ -H "Authorization: Bearer $UNITH_TOKEN" \ -H 'accept: application/json'; then ``` ```bash # scripts/delete-head.sh:71-73 if ! unith_curl -X DELETE "$API_BASE/head/$HEAD_ID" \ -H "Authorization: Bearer $UNITH_TOKEN" \ -H 'accept: application/json'; then ``` ```bash # scripts/upload-document.sh:61-64 if ! unith_curl -X POST "$API_BASE/document/upload" \ -H "Authorization: Bearer $UNITH_TOKEN" \ -F "file=@$FILE_PATH" \ -F "headId=$HEAD_ID"; then ``` ### Technical Analysis The declared service endpoint is `https://platform-api.unith.ai`, but `_utils.sh` allows any inherited `API_BASE` value to replace it. No validation requires HTTPS, verifies the destination hostname, or restricts overrides to an allowlist. All scripts subsequently trust this variable when sending sensitive data. Authentication transmits the user's account email and non-expiring UNITH secret key. Resource management calls transmit a bearer token valid for up to seven days, while document upload also transmits the selected local document. The network behavior in `delete-head.sh` ...[truncated 1319 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Hard-code `https://platform-api.unith.ai` for all credential-bearing production requests. - If endpoint overrides are required for development, require a separate explicit opt-in such as `UNITH_ALLOW_CUSTOM_API_BASE=1`. - Parse and validate the override before use: - Require the `https` scheme. - Require an exact approved hostname. - Reject embedded user information, fragments, unexpected ports, and lookalike subdomains. - Verify the effective destination immediately before adding an `Authorization` header or sensitive request body. - Never send the non-expiring secret key, bearer token, or document to an endpoint that has not passed validation. - Document any supported development endpoint and its security implications. ]]>
