T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/lib/config.sh:38
- Finding
- Unrestricted Colony credential path can cause arbitrary local file disclosure<![CDATA[ ## Vulnerability Details **File Location**: `scripts/lib/config.sh:38-44`, `scripts/adapters/colony.sh:17-29`, `scripts/adapters/colony.sh:52-54` **Related Configuration**: `bridge.json:19-22` **Vulnerability Type**: Unrestricted credential-file access and external disclosure **Risk Level**: Medium ### Vulnerable Code From `scripts/lib/config.sh:38-44`: ```bash resolve_credentials() { local cred_path cred_path="$(config_get ".platforms.${1}.credentials")" [[ -z "$cred_path" ]] && return 1 cred_path="${cred_path/#\~/$HOME}" [[ -f "$cred_path" ]] || return 1 echo "$cred_path" } ``` From `scripts/adapters/colony.sh:17-29`: ```bash get_api_key() { local cred_file cred_file="$(resolve_credentials colony)" || { # Fall back to env var [[ -n "${COLONY_API_KEY:-}" ]] && { echo "$COLONY_API_KEY"; return 0; } return 1 } # Support both plain text and JSON formats if head -1 "$cred_file" | grep -q '{'; then jq -r '.api_key // .key // .token // empty' "$cred_file" 2>/dev/null else cat "$cred_file" | tr -d '\n' fi } ``` From `scripts/adapters/colony.sh:52-54`: ```bash response=$(curl -s -w "\n%{http_code}" -X POST "$COLONY_API/auth/token" \ -H "Content-Type: application/json" \ -d "$(jq -n --arg key "$api_key" '{api_key: $key}')") ``` The default configuration at `bridge.json:19-22` is: ```json "colony": { "enabled": true, "credentials": "~/.config/colony/credentials.json", "auto_read": true } ``` ### Technical Analysis The Colony credential path is read directly from configuration and is only checked with `-f`. The implementation does not: - Restrict the path to a dedicated credential directory. - Require a specific filename or canonical path. - Reject symbolic links. - Verify file ownership or permissions. - Require a strict JSON credential schema. - Limit the amount of data read. For files not recognized as JSON by the first-line heuristic, the entire file is treated as a plaintext API key. It ...[truncated 1995 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Prefer `COLONY_API_KEY` or an operating-system credential manager instead of configurable arbitrary file paths. 2. If file-based credentials remain supported, restrict them to a dedicated user-private directory such as `~/.config/agent-bridge/credentials/`. 3. Resolve the canonical path and verify that it remains inside the approved directory. 4. Reject symbolic links and non-regular files. 5. Require a strict JSON document containing only the expected `api_key` field; remove the plaintext-file fallback. 6. Validate that the credential file is owned by the current user and is not accessible by group or other users. 7. Apply a reasonable maximum file size before reading it. 8. Treat externally supplied `BRIDGE_CONFIG` files as untrusted and require explicit user confirmation before using credential paths from them. 9. Prefer environment variables before file lookup so ordinary operation does not require filesystem credential access. ]]>
