T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/lib.sh:7
- Finding
- Bankr API key can be transmitted to an attacker-controlled endpoint<![CDATA[ ## Vulnerability Details **File Location**: `scripts/lib.sh:7-9`, `scripts/lib.sh:81-97`, `scripts/lib.sh:223-241`, and `scripts/lib.sh:244-280` **Vulnerability Type**: Unrestricted credential destination and sensitive information disclosure **Risk Level**: Medium ### Vulnerable Code The Bankr API endpoint can be overridden through an environment variable without validating its scheme or destination: ```bash AAVEGOTCHI_DIAMOND="${AAVEGOTCHI_DIAMOND:-0xA99c4B08201F2913Db8D28e71d020c4298F29dBF}" BASE_RPC_URL="${BASE_MAINNET_RPC:-https://mainnet.base.org}" BANKR_API_URL="${BANKR_API_URL:-https://api.bankr.bot}" ``` The API key is retrieved not only from the current environment but also from the user service environment and local Bankr configuration files: ```bash resolve_bankr_api_key() { local key="${BANKR_API_KEY:-}" if [ -z "$key" ] && command -v systemctl >/dev/null 2>&1; then key="$(systemctl --user show-environment 2>/dev/null | sed -n "s/^BANKR_API_KEY=//p" | head -n1 || true)" fi if [ -z "$key" ] && [ -f "$HOME/.openclaw/skills/bankr/config.json" ]; then key="$(jq -r '.apiKey // empty' "$HOME/.openclaw/skills/bankr/config.json" 2>/dev/null || true)" fi if [ -z "$key" ] && [ -f "$HOME/.openclaw/workspace/skills/bankr/config.json" ]; then key="$(jq -r '.apiKey // empty' "$HOME/.openclaw/workspace/skills/bankr/config.json" 2>/dev/null || true)" fi [ -n "$key" ] || err "BANKR_API_KEY not found in env, systemd, or Bankr config" echo "$key" } ``` Transaction submission sends the recovered credential to the configurable endpoint: ```bash submit_bankr_tx() { local to_address="$1" local calldata="$2" local description="$3" local api_key local payload api_key="$(resolve_bankr_api_key)" payload="$(jq -n \ --arg to "$to_address" \ --arg data "$calldata" \ --arg description "$description" \ '{transaction:{to:$to,chainId:8453,value:"0",data:$data},description:$description,waitForConfirmat ...[truncated 4258 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. **Pin the production API origin** - Use `https://api.bankr.bot` as a constant in production. - Do not permit ordinary runtime environment variables to redefine the destination that receives credentials. 2. **Allowlist endpoints if overrides are operationally necessary** - Parse the URL and require an exact approved scheme, hostname, and port. - Require HTTPS. - Reject user information, unexpected ports, fragments, and unapproved paths. - Maintain a small explicit allowlist rather than relying on suffix or substring matching. 3. **Separate development behavior** - Permit custom endpoints only when an explicit development or test mode is enabled. - Require separate non-production credentials in that mode. - Emit a clear warning and refuse to load production credentials for custom endpoints. 4. **Harden `curl` invocation** - Require HTTPS with options such as `--proto '=https'`. - Add `--fail-with-body`, `--show-error`, and appropriate connection and request timeouts. - Do not enable credential forwarding across redirects. Prefer rejecting redirects for authenticated API requests. 5. **Reduce credential discovery scope** - Prefer an explicitly provided secret or a dedicated secret-management interface. - Avoid automatically searching multiple configuration locations unless this fallback is essential and clearly documented. - Ensure local credential files have restrictive permissions. 6. **Apply Bankr-side least privilege** - Use narrowly scoped, short-lived, and revocable API credentials where supported. - Require independent confirmation or policy checks for asset transfers. - Rotate the key immediately if endpoint redirection or credential disclosure is suspected. ]]>
