T09 · Insecure Skill Coding Practices
Warning
- Location
- SKILL.md:15
- Finding
- API Token File May Be Created with Overly Permissive Permissions## Vulnerability Details **File Location**: `SKILL.md:15-18`; `README.md:13-16`; `scripts/generate_image.py:33,38-41`; `scripts/edit_image.py:24,45-49` **Vulnerability Type**: Insecure local credential storage **Risk Level**: Medium ### Vulnerable Code `SKILL.md:15-18` and `README.md:13-16` instruct users to store the token as follows: ```bash echo "sk-your-token" > ~/.laozhang_api_token ``` `scripts/generate_image.py:33,38-41`: ```python DEFAULT_TOKEN_PATH = Path.home() / ".laozhang_api_token" def get_api_token(): """Get API token from file""" if DEFAULT_TOKEN_PATH.exists(): return DEFAULT_TOKEN_PATH.read_text().strip() return None ``` `scripts/edit_image.py:24,45-49`: ```python DEFAULT_TOKEN_PATH = Path.home() / ".laozhang_api_token" def get_api_token(): """Get API token from file""" if DEFAULT_TOKEN_PATH.exists(): return DEFAULT_TOKEN_PATH.read_text().strip() return None ``` ### Technical Analysis Shell redirection creates `~/.laozhang_api_token` according to the user's current `umask`. With a common `umask` of `022`, the file may be created with mode `0644`, making it readable by other local users. Neither script verifies the file owner or rejects group-readable or world-readable permissions before loading the credential. The alternative `--token` option also places the token in the process command line. Depending on the operating system and process-monitoring configuration, command-line arguments may be observable by other users, monitoring agents, shell history, or diagnostic tooling. The token is intentionally transmitted as a bearer credential to `https://api.laozhang.ai/v1/chat/completions`; that transmission is required for the declared functionality and occurs over HTTPS. The weakness is the local storage and handling of the credential, not the disclosed API request itself. ### Attack Path 1. A user follows the documented command t ...[truncated 941 chars]
- Remediation
- ## Remediation Suggestions 1. Replace the documented redirection command with permission-safe creation: ```bash install -m 600 /dev/null "$HOME/.laozhang_api_token" printf '%s\n' "sk-your-token" > "$HOME/.laozhang_api_token" chmod 600 "$HOME/.laozhang_api_token" ``` 2. Before reading the file, verify that it is a regular file, is owned by the current user, and has no group or other permission bits: ```python import os import stat def get_api_token(): path = DEFAULT_TOKEN_PATH if not path.is_file(): return None info = path.stat() if info.st_uid != os.getuid(): raise PermissionError("Token file is not owned by the current user") if stat.S_IMODE(info.st_mode) & 0o077: raise PermissionError("Token file must have permissions 0600") return path.read_text(encoding="utf-8").strip() ``` 3. Prefer an operating-system credential manager or a protected environment-variable injection mechanism. 4. Discourage `--token` for routine use because process arguments and shell history can expose credentials. 5. Document token rotation and revocation procedures in case the credential is exposed.
