T09 · Insecure Skill Coding Practices
- Location
scripts/generate_image.py:34- Finding
Hard-Coded MiniMax API Credential in Root Image Generation Script
- Content
View full analysis
str: """Build the API endpoint URL.""" return f"{API_BASE_URL}" def get_api_key() -> str: """Get the MiniMax API key from environment variable, or use default.""" api_key = os.environ.get("MINIMAX_API_KEY") or DEFAULT_API_KEY if not api_key or api_key == "your-api-key-here": print("Error: MINIMAX_API_KEY environment variable not set and no default key available", file=sys.stderr) print("\nTo set it:", file=sys.stderr) print(" Windows (PowerShell): $env:MINIMAX_API_KEY = 'your-key'", file=sys.stderr) print(" Windows (CMD): set MINIMAX_API_KEY=your-key", file=sys.stderr) print(" macOS/Linux: export MINIMAX_API_KEY='your-key'", file=sys.stderr) print("\nGet your key from MiniMax dashboard:", file=sys.stderr) sys.exit(1) return api_key ``` The credential value is redacted in this report because it must be treated as compromised. ### Technical Analysis The script embeds a live-looking MiniMax API credential directly in distributed source code. The `get_api_key()` function silently selects this credential whenever `MINIMAX_API_KEY` is unset. This conflicts with the documented requirement that users supply their own API key and violates secret-management and least-privilege principles. The credential is subsequently placed in an HTTP bearer authorization header and transmitted to the declared MiniMax endpoint: ```python headers = { "Content-Type": "application/json", "Authorization": f"Bearer {api_key}" } ``` Sending a user-supplied key to the declared HTTPS API is necessary for image generation. Embedding and a ...[truncated 1056 chars]- Remediation
View remediation
str: api_key = os.environ.get("MINIMAX_API_KEY") if not api_key: raise RuntimeError("MINIMAX_API_KEY is required") return api_key ``` 4. Do not place replacement credentials in source code, examples, documentation, test fixtures, or commit history. 5. Store secrets in environment variables or an approved secret manager. 6. Add automated secret scanning to pre-commit hooks and CI release checks. 7. Review MiniMax account logs and billing records for unauthorized use. 8. If repository history has been published, remove the secret from history where practical, while recognizing that history rewriting does not replace credential revocation. ]]>
