T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/transcribe.sh:106
- Finding
- Incorrect curl End-of-Options Placement Can Expose the API Key and Break Requests<![CDATA[ ## Vulnerability Details **File Location**: `scripts/transcribe.sh`, lines 106–110 **Vulnerability Type**: Improper command-line option construction and potential credential exposure **Risk Level**: Medium ### Vulnerable Code ```bash # Call API (-- prevents option injection from filenames starting with -) http_code=$(curl -sS -w '%{http_code}' -o "$tmpfile" -- "$url" \ -H "Authorization: Token $DEEPGRAM_API_KEY" \ -H "Content-Type: ${mime}" \ --data-binary "@${in}") ``` ### Technical Analysis The `--` argument terminates curl option parsing, but it is placed before the request headers and `--data-binary` option. Arguments following the end-of-options marker can therefore be interpreted as URL operands rather than curl options. As a result: - The authorization header may not be attached to the intended Deepgram request. - The audio file may not be submitted as the HTTP request body. - The expanded `Authorization: Token $DEEPGRAM_API_KEY` argument may enter curl URL parsing, diagnostic output, or proxy-related processing. - The transcription request is likely to fail or behave inconsistently. The comment states that `--` protects against option injection through filenames. That protection is appropriate, but the marker must appear immediately before the URL after all curl options have been supplied. The audio filename is already passed as part of the quoted `--data-binary` argument and should remain before the marker. No remote script retrieval or `curl | bash` execution was found. The reviewed network operation is intended to upload audio to the declared Deepgram API, but this implementation error exceeds the necessary exposure of the API credential. ### Attack Path 1. A user configures `DEEPGRAM_API_KEY` and invokes the documented transcription script. 2. The shell expands the API key inside the authorization argument. 3. Curl encounters `--` before the authorization and body options, ending option parsing. 4. Curl may process `-H`, th ...[truncated 1191 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions Move the end-of-options marker so that all curl options precede it and the destination URL is the final operand: ```bash http_code=$(curl -sS -w '%{http_code}' -o "$tmpfile" \ -H "Authorization: Token $DEEPGRAM_API_KEY" \ -H "Content-Type: ${mime}" \ --data-binary "@${in}" \ -- "$url") ``` Additional hardening measures: 1. Add an automated test using a mocked curl executable to verify that: - Exactly one URL is requested. - The URL uses HTTPS and targets `api.deepgram.com`. - The API key is supplied only through the authorization header. - The input file is supplied as the value of `--data-binary`. 2. Ensure tests cover input and output filenames beginning with `-`, containing spaces, and containing shell metacharacters. 3. Avoid logging the complete curl argument vector or authorization header. 4. Use a narrowly scoped Deepgram API key with billing or usage limits where supported. 5. Rotate the API key if the defective command has been executed in an environment where curl diagnostics, shell tracing, or proxy logs may have captured it. ]]>
