T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/send_voice.py:31
- Finding
- Feishu Tenant Access Token Exposed Through Process Arguments## Vulnerability Details **File Location**: `scripts/send_voice.py`, lines 31-39 **Vulnerability Type**: Sensitive credential exposure through subprocess arguments **Risk Level**: Medium ### Vulnerable Code ```python def upload_file(token, opus_path): # Upload with curl because multipart handling is more complex in pure Python result = subprocess.run([ "curl", "-s", "-X", "POST", f"{FEISHU_API}/im/v1/files", "-H", f"Authorization: Bearer {token}", "-F", "file_type=opus", "-F", "file_name=voice.opus", "-F", f"file=@{opus_path}" ], capture_output=True, text=True) ``` ### Technical Analysis The Feishu tenant access token is interpolated directly into the command-line arguments supplied to `curl`. Although `subprocess.run` uses an argument array and does not invoke a shell, the resulting `curl` process still contains the complete bearer token in its process argument vector. Depending on operating-system process visibility and host configuration, another local user, monitoring agent, diagnostic utility, or compromised process may read the command line through process-listing tools or interfaces such as `/proc/<pid>/cmdline`. The exposure lasts for the duration of the upload process. Using an argument array prevents shell command injection, but it does not protect secrets placed in process arguments. Passing the authorization header this way therefore exceeds minimum safe credential-handling requirements. ### Attack Path 1. An authorized invocation of the Skill reads the Feishu application credentials and obtains a tenant access token. 2. The Skill starts `curl` with `Authorization: Bearer <token>` in its process arguments. 3. A local attacker or compromised monitoring process observes running processes while the audio upload is in progress. 4. The attacker reads the `curl` argument vector and extracts the bearer token. 5. Before the token expires, the attacker submits requests directly t ...[truncated 703 chars]
- Remediation
- ## Remediation Suggestions 1. Replace the `curl` subprocess with an in-process HTTP implementation supporting multipart uploads, such as a reviewed and pinned Python HTTP client. Set the authorization header in the client request so the token never appears in a child process argument vector. 2. If `curl` must be retained, provide sensitive headers through a protected temporary configuration file or standard input rather than command-line arguments. Create any temporary file with owner-only permissions and delete it immediately after use. 3. Avoid printing or logging authorization headers, application secrets, access tokens, or complete request objects. 4. Check the subprocess return code before parsing its output and handle malformed or unsuccessful API responses without exposing credentials. 5. Grant the Feishu application only the scopes required to upload audio and send messages. 6. Rotate or invalidate potentially exposed credentials and tokens if process command lines may have been collected by untrusted monitoring or diagnostic systems.
