T09 · Insecure Skill Coding Practices
- Location
SKILL.md:134- Finding
API Key Exposure Through Command-Line Arguments
- Content
View full analysis
``` ```python save = commands.add_parser("auth", help="保存 AI Hive API Key") save.add_argument("--api-key", required=True) save.set_defaults(handler=auth) ``` The credential is subsequently written to a local configuration file: ```python def auth(args): if not args.api_key.startswith("sk-api-") or len(args.api_key) < 20: raise SystemExit("API Key 格式错误,应为完整的 sk-api-*") CONFIG.parent.mkdir(parents=True, exist_ok=True) CONFIG.write_text( json.dumps({"api_key": args.api_key}, indent=2), encoding="utf-8" ) CONFIG.chmod(0o600) print("已安全写入", CONFIG) ``` ### Technical Analysis The documented authentication procedure requires users to supply the AI Hive API key directly through the `--api-key` command-line argument. Command-line secrets can be recorded in shell history, terminal session logs, audit records, or process-monitoring systems. On systems where process arguments are visible to other local users, the key may also be observable while the command is running. The saved configuration file is appropriately changed to permission mode `0600`, which limits subsequent file access. However, this does not protect the credential during its initial entry through the command line. The existing support for the `AI_HIVE_API_KEY` environment variable also does not eliminate the risk because the insecure command remains the documented authentication workflow. ### Attack Path 1. A user follows the documented `auth --api-key ...` command. 2. The complete API key is included in the process argument lis ...[truncated 940 chars]- Remediation
View remediation
` example from `SKILL.md`. 5. If environment-variable authentication remains supported, document its potential exposure boundaries and recommend short-lived, least-privileged credentials. 6. Preserve the existing `0600` file permissions as defense in depth, and create the file securely with restrictive permissions from the outset rather than correcting permissions only after writing. 7. Recommend rotating any key previously entered through the documented command if shell history or process logs may have been retained. ]]>
