T09 · Insecure Skill Coding Practices
- Location
src/index.ts:49- Finding
Plaintext Nostr Private Key Stored Without Enforced Restrictive Permissions
- Content
View full analysis
{ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true }); fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2)); }); } ``` ```ts const config: Config = { npub, nsec, relays: [], }; saveConfig(config); ``` ### Technical Analysis The `login` operation places the complete Nostr private key (`nsec` or hexadecimal equivalent) into the configuration object. `saveConfig` then serializes that object directly to `~/.agent-chat/config.json` in plaintext. Neither `mkdirSync` nor `writeFileSync` specifies an access mode. Consequently, effective permissions depend on the user's process umask and any permissions already present on the directory or file. Under permissive or commonly used configurations, another local account or process may be able to read the private key. Existing insecure permissions are also not corrected when the file is overwritten. Encryption of direct messages does not mitigate this issue because the exposed key is the cryptographic identity used to sign events and decrypt messages. ### Attack Path 1. A user runs the documented `agent-chat login` command with a valid private key. 2. The application stores that private key inside the `nsec` property of the configuration object. 3. `saveConfig` writes the object in plaintext to `~/.agent-chat/config.json`. 4. A malicious local user, compromised process, backup collector, or other software with access to the user's home directory reads the configuration file. 5. The attacker imports the recovered key into another Nostr client. 6. The attacker signs events as the victim and decrypts NIP-04 messages available to the attacker. ### Impact Assessment Com ...[truncated 682 chars]- Remediation
View remediation
