T09 · Insecure Skill Coding Practices
- Location
scripts/bfl-generate.sh:41- Finding
API Key Disclosure Through an Unvalidated Polling URL
- Content
View full analysis
Vulnerability Details
File Location:
scripts/bfl-generate.sh, lines 41-61
Vulnerability Type: Server-side request forgery and credential disclosure
Risk Level: Highbash POLLING_URL=$(python3 - "$REQUEST_JSON" <<'PY' import json,sys obj=json.loads(sys.argv[1]) print(obj.get('polling_url','')) PY ) REQUEST_ID=$(python3 - "$REQUEST_JSON" <<'PY' import json,sys obj=json.loads(sys.argv[1]) print(obj.get('id','')) PY ) if [[ -z "$POLLING_URL" ]]; then echo "BFL request failed:" >&2 echo "$REQUEST_JSON" >&2 exit 1 fi echo "Request ID: $REQUEST_ID" >&2 for _ in $(seq 1 240); do sleep 1 RESULT_JSON=$(curl -sS -X GET "$POLLING_URL" \ -H 'accept: application/json' \ -H "x-key: ${BFL_API_KEY}")Technical Analysis
The script obtains
polling_urlfrom a remote JSON response and passes it directly tocurlwithout verifying its scheme, hostname, port, or destination address. The request also includes the sensitiveBFL_API_KEYin thex-keyheader.This crosses a critical trust boundary: data supplied by a remote service controls the destination of a subsequent authenticated request. If the initial response is compromised or unexpectedly contains an attacker-controlled URL, the script will transmit the API key to that destination. The URL could also reference an internal or loopback service, causing the script to make requests using the host's network access.
Attack Path
- An attacker compromises, manipulates, or otherwise controls the initial BFL API response received by the script.
- The attacker supplies a
polling_urlpointing to an attacker-operated HTTPS endpoint or a service reachable only from the execution environment. - The script accepts the URL without validation.
- During polling,
curlsends a request to the supplied destination withx-key: ${BFL_API_KEY}. - For an attacker-operated end ...[truncated 617 chars]
- Remediation
View remediation
Remediation Suggestions
- Parse
polling_urlwith a URL-aware parser before using it. - Require the
httpsscheme and an explicit allowlist of expected Black Forest Labs API hostnames. - Reject URLs containing user information, unexpected ports, fragments, loopback addresses, link-local addresses, private network destinations, or hostnames that resolve to such addresses.
- Do not attach
BFL_API_KEYto any destination that has not passed validation. - If supported by the API, construct the polling endpoint locally from the trusted request ID instead of trusting a complete response-provided URL.
- Apply strict connection and overall timeouts to the polling request.
- Avoid following redirects for credential-bearing requests. If redirects are required, validate every redirect destination before forwarding credentials.
- Use a restricted API key with minimal scope and spending limits, and rotate the key if exposure is suspected.
- Parse
