T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/hienergy_skill.py:1651
- Finding
- API Key Exposed Through Command-Line Arguments<![CDATA[ ## Vulnerability Details **File Location**: `scripts/hienergy_skill.py:1651-1658` **Vulnerability Type**: Command-line credential exposure **Risk Level**: Medium ### Vulnerable Code ```python # Check if API key is provided if len(sys.argv) > 1: api_key = sys.argv[1] else: api_key = os.environ.get('HIENERGY_API_KEY') if not api_key: print("Usage: python hienergy_skill.py <api_key>") print("Or set HIENERGY_API_KEY environment variable") ``` ### Technical Analysis The script accepts the HiEnergy API key as a positional command-line argument and explicitly recommends this invocation through its usage message. Command-line arguments are not an appropriate channel for secrets because they may be exposed through: - Shell command history. - Process inspection utilities and operating-system process metadata. - Process accounting and endpoint-monitoring products. - CI/CD command logs. - Terminal session recording and diagnostic collection. Although the script also supports an environment variable, the positional argument takes precedence and the displayed usage encourages users to expose the credential. ### Attack Path 1. A user follows the displayed instruction and runs: ```bash python scripts/hienergy_skill.py <real-api-key> ``` 2. The command, including the key, is retained in shell history or process-monitoring data. 3. Another local user, administrator, monitoring agent, support operator, or log reader obtains the argument. 4. The exposed key is replayed against `https://app.hienergy.ai/api/v1`. 5. The attacker receives the same API permissions and data access assigned to the compromised HiEnergy account. This path requires access to local process information, history, or collected logs; it does not provide remote code execution by itself. ### Impact Assessment A recovered key can authorize access to the account-scoped HiEnergy API. Depending on the compromised account's server-side privileges, this can expose adverti ...[truncated 347 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove positional command-line support for the API key. 2. Require `HIENERGY_API_KEY` or the documented alias from a protected environment or secret manager. 3. Replace the usage message with: ```python api_key = ( os.environ.get("HIENERGY_API_KEY") or os.environ.get("HI_ENERGY_API_KEY") ) if not api_key: print("Set HIENERGY_API_KEY in a protected environment.") sys.exit(1) ``` 4. If interactive entry is necessary, use `getpass.getpass()` so the key is not echoed or stored in command history. 5. Document secure secret injection for CI/CD systems. 6. Rotate any key that has previously been supplied on a command line. ]]>
