T09 · Insecure Skill Coding Practices
- Location
scripts/translate.py:184- Finding
Cohere API Key Exposed Through Process Command-Line Arguments
- Content
View full analysis
Vulnerability Details
File Location:
scripts/translate.py:184-190
Vulnerability Type: Credential exposure through child-process arguments
Risk Level: MediumVulnerable 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-364also 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_KEYenvironment 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-keyinterface 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
- A victim starts a translation using a valid Cohere API key.
- The script launches curl and places
Authorization: bearer <API_KEY>in its argument vector. - While curl is running, a local attacker or compromised monitoring process with sufficient process-inspection access captures the command-line arguments.
- Alternatively, if the victim uses
--api-key, the attacker retrieves t ...[truncated 938 chars]
- Remediation
View remediation
Remediation Suggestions
- 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.requestwould preserve the project's no-external-Python-dependencies design. - Remove or deprecate the
--api-keyoption. Prefer a protected environment variable, operating-system credential store, or non-echoing interactive prompt. - If curl must remain, avoid passing credentials through argv. Supply sensitive curl configuration through a protected mechanism such as a mode-
0600temporary configuration file, then delete it reliably in afinallyblock. Avoid leaving credentials in ordinary temporary files. - Ensure exceptions and diagnostics never include authorization headers or raw credentials.
- 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.
- Rotate any credential that may already have been exposed through process logs, shell history, or monitoring telemetry.
- 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
