T09 · Insecure Skill Coding Practices
Error
- Location
- wallet.js:3
- Finding
- Generated Private Key Exposed Through Process Logs## Vulnerability Details **File Location**: `wallet.js:3-6` **Vulnerability Type**: Plaintext disclosure of cryptographic credentials **Risk Level**: High ### Vulnerable Code ```js const wallet = ethers.Wallet.createRandom(); console.log("Address:", wallet.address); console.log("Private Key:", wallet.privateKey); ``` ### Technical Analysis The wallet utility writes the complete private key to standard output. Private keys are bearer credentials: possession of the key is sufficient to sign arbitrary blockchain transactions as the corresponding wallet. Standard output may be captured by shell history tooling, terminal recording, CI/CD job logs, container logging drivers, process supervisors, or centralized observability services. Consequently, systems and users that are not authorized to control the wallet may still obtain its private key. ### Attack Path 1. A user runs `node wallet.js`. 2. The generated private key is written to standard output. 3. A terminal recorder, CI system, container runtime, process supervisor, or another user with log access retains or reads the output. 4. The attacker imports the disclosed private key into a wallet or signing tool. 5. If assets are subsequently transferred to the generated address, the attacker signs transactions that transfer those assets elsewhere. ### Impact Assessment Disclosure provides complete control over the generated wallet. An attacker can transfer native currency and tokens, authorize token allowances, interact with contracts, and impersonate the wallet in cryptographic authentication workflows. The scope is limited to the generated wallet and any permissions or assets associated with it, but compromise is irreversible unless assets and authorities are migrated before exploitation.
- Remediation
- ## Remediation Suggestions - Never print private keys, seed phrases, or unencrypted keystore material. - Print only the public wallet address. - Store generated keys in an encrypted JSON keystore protected by a strong user-supplied password. - Apply restrictive filesystem permissions to any keystore file. - Prefer an operating-system secret store, hardware wallet, or managed signing service for production funds. - Configure logging systems to redact recognized secret formats. - Treat every key previously exposed to logs as compromised and replace it before funding the address.
