T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/translate.py:184
- Finding
- Cohere API Key Exposed Through Process Command-Line Arguments## Vulnerability Details **File Location**: `scripts/translate.py:184-190` **Vulnerability Type**: Credential exposure through child-process arguments **Risk Level**: Medium ### Vulnerable Code ```python result = subprocess.run( ["curl", "-s", "--request", "POST", API_URL, "--header", "accept: application/json", "--header", "content-type: application/json", "--header", f"Authorization: bearer {api_key}", "--data", json.dumps(payload)], capture_output=True, text=True, timeout=120 ) ``` The related CLI option at `scripts/translate.py:363-364` also allows the key to be supplied directly as a Python process argument: ```python parser.add_argument("--api-key", default=None, help="Cohere API key (or set COHERE_API_KEY env var)") ``` ### Technical Analysis The script interpolates the Cohere API key into curl's argument vector as an HTTP authorization header. Consequently, even when the credential originates from the `COHERE_API_KEY` environment variable, it becomes part of the curl child process's command-line arguments. Depending on operating-system process visibility and hardening settings, another local user or process may be able to inspect these arguments through process-listing utilities, process-monitoring software, audit telemetry, or process metadata exposed by the operating system. The optional `--api-key` interface creates an additional exposure path because the credential may appear in the Python process arguments, shell history, terminal logs, job-control records, and endpoint monitoring data. ### Attack Path 1. A victim starts a translation using a valid Cohere API key. 2. The script launches curl and places `Authorization: bearer <API_KEY>` in its argument vector. 3. While curl is running, a local attacker or compromised monitoring process with sufficient process-inspection access captures the command-line arguments. 4. Alternatively, if the victim uses `--api-key`, the attacker retrieves t ...[truncated 938 chars]
- Remediation
- ## Remediation Suggestions 1. Replace the curl subprocess with an in-process HTTPS client so the authorization header is transmitted without placing it in a child process's argument vector. A standard-library implementation using `urllib.request` would preserve the project's no-external-Python-dependencies design. 2. Remove or deprecate the `--api-key` option. Prefer a protected environment variable, operating-system credential store, or non-echoing interactive prompt. 3. If curl must remain, avoid passing credentials through argv. Supply sensitive curl configuration through a protected mechanism such as a mode-`0600` temporary configuration file, then delete it reliably in a `finally` block. Avoid leaving credentials in ordinary temporary files. 4. Ensure exceptions and diagnostics never include authorization headers or raw credentials. 5. Document that API keys must not be entered directly on the command line and recommend short-lived or narrowly scoped credentials where the provider supports them. 6. Rotate any credential that may already have been exposed through process logs, shell history, or monitoring telemetry.
