T09 · Insecure Skill Coding Practices
- Location
src/crypto/IdentityManager.ts:191- Finding
Unencrypted Nostr Private Key Stored with Unrestricted Default File Permissions
- Content
View full analysis
{ if (!this.identity) return; // Convert the private key to base64 for JSON serialization const data = { ...this.identity, nostr: this.identity.nostr ? { pubkey: this.identity.nostr.pubkey, privateKey: Buffer.from(this.identity.nostr.privateKey).toString('base64'), } : undefined, }; await writeFile(this.identityPath, JSON.stringify(data, null, 2)); } ``` ### Technical Analysis The persistent identity file contains the complete Nostr private key encoded with Base64. Base64 only changes the representation of data and provides no encryption or confidentiality. The call to `writeFile` does not specify a restrictive file mode. Consequently, the resulting permissions depend on the process umask and deployment environment. On systems with permissive defaults, other local users or processes may be able to read `~/.osm-p2p/identity.json`. Possession of the Nostr private key is sufficient to create valid signatures under the victim's public key. There is no password-derived encryption, operating-system keychain integration, or hardware-backed protection. ### Attack Path 1. The victim starts the application, causing `IdentityManager.save()` to create `~/.osm-p2p/identity.json`. 2. A local attacker, compromised process, backup reader, or container co-tenant obtains read access to that file. 3. The attacker extracts the `nostr.privateKey` property. 4. The attacker Base64-decodes the value. 5. The recovered key is used to sign Nostr events as the victim and impersonate the node. ### Impact Assessment An attacker who reads the file can obtain the full signing authority of the affected Nostr identity. This permits persistent identity impersonation, forged announcements, forged messages, and abuse o ...[truncated 311 chars]- Remediation
View remediation
