T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/anysearch_cli.sh:38
- Finding
- API Key Exposure Through Process Command-Line Arguments<![CDATA[ ## Vulnerability Details **File Location**: `scripts/anysearch_cli.sh:38-54`, `scripts/anysearch_cli.sh:98`, `scripts/anysearch_cli.sh:159`, `scripts/anysearch_cli.sh:184`, `scripts/anysearch_cli.sh:209`, and `scripts/anysearch_cli.py:203` **Vulnerability Type**: Credential exposure through process arguments **Risk Level**: Medium ### Vulnerable Code ```bash _call_api() { local tool_name="$1" local arguments="$2" local auth_args=() if [[ -n "$API_KEY" ]]; then auth_args+=(-H "Authorization: Bearer $API_KEY") fi local payload payload=$(jq -n --arg name "$tool_name" --argjson args "$arguments" \ '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":$name,"arguments":$args}}') local response response=$(curl -s -X POST "$ENDPOINT" \ -H "Content-Type: application/json" \ "${auth_args[@]}" \ -d "$payload" \ --max-time 30 2>/dev/null) ``` The shell command handlers also accept the secret directly through a command-line option: ```bash --api_key) API_KEY="$2"; shift 2 ;; ``` The Python implementation exposes the same user-facing option: ```python parser.add_argument("--api_key", default=os.environ.get("ANYSEARCH_API_KEY", ""), help="API key (optional)") ``` ### Technical Analysis The Bash implementation constructs an `Authorization` header containing the AnySearch API key and passes that header to `curl` as a command-line argument. As a result, even a key originally loaded from a protected environment file is copied into the argument vector of the spawned `curl` process. Depending on operating-system settings, process arguments can be visible through process inspection utilities, process accounting, endpoint monitoring, diagnostic collection, crash reports, or command execution logs. The explicitly supported `--api_key` option introduces an additional exposure route because the secret may also be recorded in shell history and appears in the parent CLI process arguments. This network authent ...[truncated 1304 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove the `--api_key` option from both implementations to prevent secrets from being placed in shell history and parent-process arguments. 2. Accept credentials only through a protected environment variable, operating-system credential store, or dedicated secret manager. 3. In the Bash implementation, do not place the authorization header directly in `curl`'s argument vector. Prefer an in-process HTTP client or another mechanism that does not disclose the header through process metadata. 4. If a temporary curl configuration or header file must be used, create it with restrictive permissions such as mode `0600`, avoid predictable names, and delete it reliably with a `trap`. 5. Document that users should rotate any API key previously supplied through `--api_key`. 6. Ensure operational logging and error handling never print authorization headers or secret-bearing command lines. ]]>
