T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/build_hub.py:167
- Finding
- Discord Bot Token Exposed Through Command-Line Arguments<![CDATA[ ## Vulnerability Details **File Location**: `scripts/build_hub.py:167-170`; documented invocation in `SKILL.md:38-48` **Vulnerability Type**: Credential exposure through process arguments and shell history **Risk Level**: Medium ### Vulnerable Code ```python parser.add_argument("--token", required=True, help="Discord bot token") parser.add_argument("--guild", required=True, help="Guild (server) ID") parser.add_argument("--dry-run", action="store_true", help="Preview without creating") args = parser.parse_args() build_hub(args.token, args.guild, args.dry_run) ``` The documented commands reinforce this unsafe credential-handling method: ```bash python3 scripts/build_hub.py --token BOT_TOKEN --guild GUILD_ID --dry-run ``` ```bash python3 scripts/build_hub.py --token BOT_TOKEN --guild GUILD_ID ``` ### Technical Analysis The Skill requires users to provide a Discord bot token as a command-line argument. Command-line arguments are not an appropriate channel for long-lived credentials because they may be exposed through: - Shell command history. - Process inspection interfaces and monitoring tools. - Terminal session capture. - CI/CD job logs or command tracing. - Diagnostic and endpoint-management software that records process arguments. The token is an administrative credential used with permissions including channel management, role management, message sending, and message pinning. Although the token is sent only to Discord's hardcoded official HTTPS API, its local handling creates an avoidable disclosure risk. ### Attack Path 1. A user follows `SKILL.md` and invokes the script with `--token BOT_TOKEN`. 2. The complete command is retained in shell history, captured by logging, or temporarily visible through process inspection. 3. An attacker with access to that local information obtains the bot token. 4. The attacker sends authenticated requests to the Discord REST API as the bot. 5. The attacker exercises whichever permissions have been assigne ...[truncated 658 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove the `--token` command-line argument. 2. Read the token from a protected environment variable or operating-system secret store. 3. Alternatively, request it using `getpass.getpass()` so it is not echoed or retained in shell history. 4. Ensure CI/CD systems inject the credential through masked secret variables rather than command text. 5. Avoid printing, logging, or including the token in exception messages. 6. Update `SKILL.md` to show a safe invocation pattern, for example: ```python import os import getpass token = os.environ.get("DISCORD_BOT_TOKEN") if not token: token = getpass.getpass("Discord bot token: ") ``` ```bash export DISCORD_BOT_TOKEN='...' python3 scripts/build_hub.py --guild GUILD_ID --dry-run ``` 7. Advise users who have already supplied the token on the command line to clear relevant history and logs and rotate the token through the Discord developer portal. ]]>
