T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/imgbb.py:73
- Finding
- Insecure API Key Handling Through Process Arguments and Plaintext Configuration<![CDATA[ ## Vulnerability Details **File Location**: `scripts/imgbb.py:73-87`; related documentation at `SKILL.md:38-40` and `SKILL.md:68` **Vulnerability Type**: API key exposure through command-line arguments and insecure plaintext storage **Risk Level**: Medium ### Vulnerable Code ```python def main(): parser = argparse.ArgumentParser(description='ImgBB API Client') parser.add_argument('image', nargs='?', help='Path to image file') parser.add_argument('--key', help='ImgBB API key (or use IMGBB_API_KEY env or ~/.imgbb_api_key)') parser.add_argument('--url', help='Upload from URL') parser.add_argument('--base64', help='Upload from Base64 string') parser.add_argument('--name', help='Custom name') parser.add_argument('--expiration', type=int, default=0, help='Expiration in seconds') parser.add_argument('--json', action='store_true', help='JSON output') parser.add_argument('--batch', metavar='FOLDER', help='Batch upload folder') parser.add_argument('--ext', default='.jpg', help='File extension for batch') parser.add_argument('--set-key', metavar='KEY', help='Save API key to config file') args = parser.parse_args() # Save API key if requested if args.set_key: with open(CONFIG_FILE, 'w') as f: f.write(args.set_key) ``` The documentation also recommends secret-bearing commands: ```bash echo "your_api_key" > ~/.imgbb_api_key python imgbb.py image.jpg --key YOUR_KEY ``` ### Technical Analysis The `--key` and `--set-key` options accept an API credential directly as a process argument. Command-line arguments can be exposed through shell history, process inspection utilities, terminal logging, monitoring software, diagnostic collection, and audit infrastructure. This makes process arguments unsuitable for transmitting persistent secrets. The `--set-key` implementation writes the credential to `~/.imgbb_api_key` as plaintext without explicitly applying owner-only permissions. The resul ...[truncated 1834 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove or deprecate the `--key` and `--set-key KEY` interfaces so credentials are not passed through process arguments. 2. Prefer `IMGBB_API_KEY`, an operating-system credential manager, or an interactive prompt implemented with `getpass.getpass()`. 3. If file-based storage must remain, create the file atomically with owner-only mode `0600`, for example with `os.open()` using `O_CREAT | O_WRONLY | O_TRUNC` and an explicit mode. 4. Before writing, verify that an existing path is a regular file owned by the current user and reject symbolic links or unexpected file types. 5. Consider creating a dedicated configuration directory with mode `0700`. 6. Update `SKILL.md` to stop recommending `--key`, `--set-key`, and direct `echo` commands containing secrets. 7. Advise affected users to remove exposed commands from shell history, restrict existing file permissions with `chmod 600 ~/.imgbb_api_key`, and rotate any key that may already have been exposed. ]]>
