T09 · Insecure Skill Coding Practices
- Location
scripts/check_token_plan_quota.py:63- Finding
Credential setup guidance can overwrite existing secrets and create an insufficiently protected key file
- Content
View full analysis
~/.openclaw/.env ``` ``` From `scripts/check_token_plan_quota.py:63-69`: ```python print( f"未找到 {ENV_FILE_HINT}(实际路径:{DEFAULT_ENV_FILE})。请先创建并填写,例如:", file=sys.stderr, ) print( 'mkdir -p ~/.openclaw && printf "MINIMAX_API_KEY=你的key\\n" > ~/.openclaw/.env', file=sys.stderr, ) ``` ### Technical Analysis The recommended shell command uses the `>` redirection operator to write the API key. This truncates `~/.openclaw/.env` before writing the new value. Although the script only prints the command rather than executing it automatically, a user following the documented guidance can erase other credentials and configuration already stored in that file. The command also does not explicitly secure the directory or file permissions. The resulting access mode depends on the user's current `umask`. With a permissive `umask`, the `.env` file may be readable by other local users, exposing the MiniMax API key. The guidance is especially unsafe when the file exists but merely lacks `MINIMAX_API_KEY`, because the documentation still recommends replacing the entire file rather than safely editing or appending to it. ### Attack Path 1. The user invokes the quota-checking script without a resolvable MiniMax API key. 2. The script prints the credential setup command, or the user copies the equivalent command from `SKILL.md`. 3. The user executes the command. 4. If `~/.openclaw/.env` already exists, shell redirection truncates it and deletes any other environment variables or credentials. 5. If the user's `umask` permits grou ...[truncated 813 chars]- Remediation
View remediation
` redirection for an existing shared environment file. - Instruct the user to edit the file with a text editor, or append the variable only after confirming that the key is absent. - Create the credential directory with mode `0700` and the credential file with mode `0600`. - Avoid embedding a real secret directly in a shell command, since commands may be retained in shell history. - Detect an existing `MINIMAX_API_KEY` entry before appending to avoid duplicate or conflicting definitions. - Use guidance similar to: ```bash mkdir -p ~/.openclaw chmod 700 ~/.openclaw touch ~/.openclaw/.env chmod 600 ~/.openclaw/.env printf '%s\n' 'MINIMAX_API_KEY=replace-with-your-key' >> ~/.openclaw/.env ``` This example should only be recommended after confirming that the variable does not already exist. Preferably, tell the user to open the file in an editor and add the value manually. The script's printed guidance and `SKILL.md` must be updated together so they do not provide conflicting security instructions. ]]>
