T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/wallet.py:18
- Finding
- Trading Wallet Private Key Is Stored in Plaintext<![CDATA[ ## Vulnerability Details **File Location**: `scripts/wallet.py:18-45` **Vulnerability Type**: Plaintext storage of sensitive credentials **Risk Level**: High ### Vulnerable Code ```python def generate_wallet(): """Generate a new trading wallet.""" account = Account.create() wallet_data = { "address": account.address, "private_key": account.key.hex(), "note": "DEX Agent trading wallet. NEVER share this key. Generated locally." } WALLET_DIR.mkdir(exist_ok=True) with open(WALLET_FILE, "w") as f: json.dump(wallet_data, f, indent=2) os.chmod(WALLET_FILE, 0o600) print(f"✅ Wallet generated: {account.address}") print(f" Saved to: {WALLET_FILE}") print(f" ⚠️ Fund this wallet with ETH (for gas) and USDC (for trading)") return account.address def load_wallet(): """Load the trading wallet.""" if not WALLET_FILE.exists(): print("❌ No wallet found. Run: python3 wallet.py generate") return None, None with open(WALLET_FILE) as f: data = json.load(f) return data["address"], data["private_key"] ``` ### Technical Analysis The raw private key is serialized directly into `wallets/trading-wallet.json`. Although the file is assigned mode `0600`, this is an access-control measure rather than encryption. It does not protect the key from processes running as the same operating-system user, compromised backups, accidental archive publication, filesystem disclosure vulnerabilities, or malicious local dependencies. This also contradicts the module statement that private keys are stored in encrypted form. ### Attack Path 1. The user runs the wallet-generation command. 2. The Skill writes the raw hexadecimal private key to `scripts/wallets/trading-wallet.json`. 3. An attacker obtains same-user filesystem access, compromises a backup, or exploits another local file-read weakness. 4. The attacker reads and imports the private key into another wallet. 5. ...[truncated 429 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Replace raw-key JSON storage with an encrypted Web3 keystore using a strong user-supplied passphrase. - Prefer an operating-system keychain, hardware wallet, HSM, or external signer for production funds. - Keep decrypted key material in memory only for the shortest practical duration. - Ensure wallet and parent-directory permissions are restrictive before writing sensitive data. - Use atomic file creation with exclusive-create semantics. - Update documentation so that it accurately describes the implemented key-protection model. - Warn existing users to migrate funds to a newly generated, securely managed wallet if the plaintext file may have been exposed. ]]>
