T09 · Insecure Skill Coding Practices
Error
- Location
- index.ts:67
- Finding
- AES Master Key Disclosed Through Application Logs<![CDATA[ ## Vulnerability Details **File Location**: `index.ts:67-72` **Vulnerability Type**: Plaintext disclosure of cryptographic key material **Risk Level**: High ### Vulnerable Code ```typescript const randomKey = crypto.getRandomValues(new Uint8Array(32)); keyStr = encodeHex(randomKey); Deno.env.set("OPENCLAW_ENV_ENCRYPTION_KEY", keyStr); console.warn("⚠️ 自动生成环境变量加密密钥,请保存到安全位置:", keyStr); console.warn("⚠️ 重启后如果没有设置此密钥,加密的环境变量将无法解密!"); ``` ### Technical Analysis When no custom key or `OPENCLAW_ENV_ENCRYPTION_KEY` environment variable is present, the implementation generates an AES-256 key and writes the complete key to standard error through `console.warn`. Cryptographic keys must not be included in application logs. Standard error is frequently captured by container runtimes, CI systems, centralized logging services, process supervisors, or agent conversation infrastructure. Access controls and retention rules for these systems are often weaker than those applied to secret-management systems. Possession of this key destroys the confidentiality boundary provided by AES-GCM for every value encrypted under the same key. Storing the key in the process environment also increases its exposure to other code running with access to that environment. ### Attack Path 1. An attacker or ordinary caller invokes any action before encryption has been initialized, or explicitly invokes the `init` action without supplying a key. 2. The implementation generates a new AES key. 3. The complete key is emitted to standard error. 4. The execution environment captures standard error in local, CI, container, or centralized logs. 5. An attacker with access to those logs obtains the AES key. 6. If the attacker can also obtain encrypted records and their IVs through memory disclosure, debugging output, a later persistence layer, or another application flaw, the attacker can decrypt every record protected by that key. ### Impact Assessment The disclosed value is the master ...[truncated 375 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Never print encryption keys, passwords, tokens, plaintext secrets, or equivalent key material to any output stream. - Remove the key argument from the warning and log only a non-sensitive initialization status. - Obtain the key from a dedicated secret manager, protected runtime secret, or externally injected key file with restrictive permissions. - Avoid placing newly generated keys into the general process environment when a narrower storage mechanism is available. - If automatic generation is required, return the key only through an explicitly protected provisioning channel and never through normal application responses or logs. - Rotate any key that may already have appeared in logs. - Remove historical key-bearing log records where possible and review access logs for unauthorized retrieval. - Add automated tests or secret-scanning rules that fail builds when cryptographic keys or secret values are passed to logging functions. ]]>
