T09 · Insecure Skill Coding Practices
- Location
scripts/amap_weather.py:148- Finding
API Key Exposure Through Command-Line Arguments
- Content
View full analysis
str: key = args_key or os.environ.get("AMAP_API_KEY", "") if not key: print("错误: 未提供 API Key。请设置 AMAP_API_KEY 环境变量或使用 --key 参数。", file=sys.stderr) sys.exit(1) return key ``` ```python parser.add_argument("--key", help="高德 API Key(也可用 AMAP_API_KEY 环境变量)") ``` ```python key = get_api_key(args.key) ``` ### Technical Analysis The script permits users to supply the Amap API key through the `--key` command-line option. Command-line arguments are not an appropriate secret transport mechanism because they may be exposed through: - Process inspection interfaces and process-listing utilities. - Shell command history. - System auditing and endpoint-monitoring telemetry. - Job runners, wrapper scripts, diagnostic output, or execution logs. - Error reports that capture the complete invoked command. The key is subsequently included in an HTTPS query sent to the documented Amap endpoint. That transmission is necessary for the declared weather-query functionality and is protected in transit by TLS. No transmission to an unrelated destination was found. The vulnerability is specifically the optional command-line ingestion mechanism, not the required Amap API request. ### Attack Path 1. A user invokes the Skill with a command such as `python3 scripts/amap_weather.py Beijing --key SECRET`. 2. The shell records the command in history, or the operating system exposes the process argument vector while the process is running. 3. A local user, monitoring agent, audit service, CI system, or log collector with access to that information captures the key. 4. The observer submits requests authenticated with the exposed key to Amap services for which that key is authorized. 5. The attacker consumes ...[truncated 687 chars]- Remediation
View remediation
