T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/generate-address.py:255
- Finding
- Wallet private keys and mnemonic phrases are exposed through plaintext output and files<![CDATA[ ## Vulnerability Details **File Location**: `scripts/generate-address.py:255-300`; related examples in `SKILL.md:30-37` and `references/kaspa-python-sdk.md:212-217, 572-582` **Vulnerability Type**: Plaintext disclosure and insecure storage of wallet secrets **Risk Level**: High ### Vulnerable Code ```python for i in range(args.count): address, wif, private_key = generator.generate_address(compressed) result = { 'index': i + 1, 'address': address, 'private_key_wif': wif, 'private_key_hex': private_key.hex(), 'network': args.network, 'compressed': compressed } results.append(result) if args.format == 'text': print(f"Address {i + 1}:") print(f" Address: {address}") print(f" Private Key: {wif}") print(f" Hex: {private_key.hex()}") print() if args.output: if args.format == 'json': import json with open(args.output, 'w') as f: json.dump(results, f, indent=2) elif args.format == 'csv': import csv with open(args.output, 'w', newline='') as f: writer = csv.DictWriter(f, fieldnames=results[0].keys()) writer.writeheader() writer.writerows(results) else: with open(args.output, 'w') as f: for result in results: f.write(f"Address: {result['address']}\n") f.write(f"Private Key: {result['private_key_wif']}\n") f.write(f"Hex: {result['private_key_hex']}\n") f.write("\n") print(" These keys are generated locally and are not stored anywhere.") ``` The documentation also encourages secret logging: ```javascript console.log('Private Key:', privateKey.toString()); ``` ```python print(f"Private Key: {private_key.hex()}") print(f"Mnemonic: {' '.join(mnemonic)}") ``` ### Technical Analysis A WIF private key, raw private key, or mnemonic phrase provides complete control o ...[truncated 1508 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Do not display private keys or mnemonics by default. Require an explicit, strongly worded opt-in for secret export. - Prefer encrypted wallet files or integration with an operating-system key store or hardware wallet. - If plaintext export is unavoidable, create the file atomically with mode `0600`, reject existing files, and verify permissions after creation. - Never print both WIF and raw hexadecimal forms. - Warn users that terminal output and files may be retained by logs and backups. - Remove the inaccurate “not stored anywhere” statement when an output file is used. - Replace documentation examples that print private keys or mnemonic phrases with examples that print only public addresses. - Clear or minimize the lifetime of secret-containing objects where supported by the SDK. ]]>
