T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/generate_image.py:323
- Finding
- API Credential Exposure Through Command-Line Arguments## Vulnerability Details **File Location**: `SKILL.md:217-222`, `scripts/generate_image.py:323`, `scripts/generate_image.js:270-274` **Vulnerability Type**: API credential exposure through process arguments and shell history **Risk Level**: Medium The Skill documents and implements an optional `-k` / `--api-key` argument that allows users to place an API credential directly on the command line. ### Vulnerable Code `SKILL.md:217-222`: ```bash **Command-line argument method (temporary):** ```bash python scripts/generate_image.py -p "一只猫" -k "your-api-key-here" ``` ``` `scripts/generate_image.py:323`: ```python parser.add_argument("--api-key", "-k", default=None, help="API密钥(覆盖环境变量)") ``` `scripts/generate_image.js:270-274`: ```javascript if (a === '-k' || a === '--api-key') { args.apiKey = requireValue(i, a); i++; continue; } ``` ### Technical Analysis Command-line arguments are not an appropriate channel for sensitive credentials. Depending on the operating system and its access controls, command arguments may be exposed through: - Shell history files. - Process inspection utilities and process metadata. - Terminal logging or session recording. - Diagnostic and monitoring software. - Automation logs that record invoked commands. The code does not print the API key or include it in its sanitized request-payload log. Nevertheless, accepting the credential as a process argument exposes it before and during program execution. The documentation increases the likelihood of exposure by explicitly recommending an invocation containing the secret. The scripts also support the safer `APIYI_API_KEY` environment variable. Consequently, command-line credential handling is not necessary for the Skill's declared image-generation and image-editing functionality and exceeds the minimum credential interface required. ### Attack Path 1. A user follows the documented example and invokes the sc ...[truncated 1087 chars]
- Remediation
- ## Remediation Suggestions 1. Remove the `-k` / `--api-key` option from both the Python and Node.js implementations. 2. Remove the command-line credential example from `SKILL.md` and from both scripts' help text. 3. Continue accepting the credential through `APIYI_API_KEY`, or integrate with an operating-system credential manager or protected secret store. 4. If interactive use is required, read the key from a non-echoing prompt rather than from command arguments. 5. Ensure diagnostic output, exception handling, and request logging never include the `Authorization` header. 6. Advise users who previously used the documented command-line option to: - Rotate the affected API key. - Remove relevant entries from shell history where feasible. - Review terminal, CI/CD, and process-monitoring logs for retained credentials. 7. Apply service-side quota limits, key scoping, expiration, and usage alerts to reduce the impact of future credential disclosure.
