Back to skill

Security audit

Nostr Nak

Security checks for vulnerabilities and agentic risk

Overview

The skill has a coherent Nostr CLI purpose, but it under-discloses risky private-key handling and encourages shell-string command templates that can be unsafe with user-supplied values.

Review before installing. Only use this skill if you can keep Nostr private keys out of prompts, command history, logs, and transcripts, and ensure any user-provided relay or key values are strictly validated and shell-escaped before being used in `script -c` commands. Prefer safer signer or credential-storage workflows when posting.

Vulnerability Patterns
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (2)

T09 · Insecure Skill Coding Practices

Error
Location
SKILL.md:19
Finding
Private Nostr Keys Exposed Through Command-Line Arguments<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md`, lines 19–21 **Vulnerability Type**: Sensitive credential exposure through process arguments **Risk Level**: High ### Vulnerable Code Snippet ```markdown ## Identity Handling - **Querying**: Use `npub...` or hex pubkey with the `-a` flag. - **Posting**: Use `nsec...` or hex private key with the `--sec` flag. ``` ### Technical Analysis The skill instructs the agent to provide a Nostr private key directly to the `nak` command through the `--sec` command-line option. Command-line arguments can be visible through local process-inspection interfaces and may also be captured by terminal logs, PTY session recording, debugging systems, audit tooling, or command-history mechanisms. The exposure risk is increased by the required `script -c` wrapper because the full command is passed as a string through an additional process and shell execution layer. The project does not provide instructions for preventing the private key from being logged or retained. ### Attack Path 1. A user supplies an `nsec` or hexadecimal Nostr private key for a posting operation. 2. The agent constructs a `nak` command containing the key as the value of `--sec`. 3. The command is passed through the documented `script -c` PTY wrapper. 4. A local process observer, logging system, debugging facility, or retained session record captures the command argument. 5. An attacker obtains the private key and uses it independently to sign and publish Nostr events as the victim. ### Impact Assessment Disclosure of the private key grants control of the corresponding Nostr identity. An attacker could impersonate the victim, publish fraudulent signed events, alter identity metadata, or perform any other action authorized by that key. The issue does not itself provide elevated operating-system privileges. Its scope is the Nostr identity controlled by the exposed key, although subsequent social or operational consequences may extend beyond the ...[truncated 16 chars]
Remediation
<![CDATA[ ## Remediation Suggestions - Do not accept or embed raw `nsec` or hexadecimal private keys in command-line arguments. - Prefer a supported external signer, hardware-backed signer, or operating-system credential store. - If `nak` supports secret input through a protected file descriptor, standard input, environment-independent signer, or restricted credential file, use that mechanism instead of `--sec`. - Ensure that secret-bearing commands are excluded from shell history, PTY transcripts, debug logs, telemetry, and audit output. - Document that users must never provide private keys in prompts or other persistently recorded interfaces. - Apply restrictive permissions to any unavoidable temporary credential resource and securely remove it immediately after use. ]]>

T09 · Insecure Skill Coding Practices

Error
Location
SKILL.md:9
Finding
Shell Command Injection Through Unvalidated Values in the PTY Command Template<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md`, lines 9–17 **Vulnerability Type**: Shell command injection **Risk Level**: High ### Vulnerable Code Snippet ```markdown ## Critical Technical Note (PTY Requirement) `nak` hangs in non-interactive environments due to stdout buffering. **Always** wrap `nak` commands in `script` to force a pseudo-TTY: `script -q -c "nak req ..." /dev/null | cat` ## Relay Logic By default, use discovery relays if no relay is specified: - `wss://relay.damus.io` - `wss://relay.primal.net` - `wss://relay.nostr.band` If the user specifies a relay, override these defaults. ``` The same unsafe construction pattern is demonstrated again at line 28: ```markdown `script -q -c "nak req -k 1 -a <npub> <relays> -l 5" /dev/null | cat` ``` ### Technical Analysis The `-c` option supplies `script` with a single command string that is interpreted through a shell. The documented template places variable values such as public keys and relay addresses inside that shell command without requiring strict format validation or shell-safe escaping. The skill explicitly permits users to override the default relays. If an agent directly substitutes a user-controlled relay or public-key value into the template, shell metacharacters, substitutions, quoting characters, or command separators can escape the intended `nak` invocation and introduce additional commands. This is a command-construction weakness in the skill instructions rather than executable source code shipped by the package. Exploitation therefore depends on an implementing agent inserting untrusted input into the template without sanitization, as the current instructions allow. ### Attack Path 1. An attacker asks the agent to use a specially crafted relay or identifier containing shell syntax. 2. The agent follows the skill instructions and substitutes that value into the `script -q -c "nak req ..."` command string. 3. `script -c` passes the constructed string to a shell. ...[truncated 733 chars]
Remediation
<![CDATA[ ## Remediation Suggestions - Do not concatenate raw user input into a command passed to `script -c`. - Validate relay values with a strict parser and permit only valid `wss://` URLs with acceptable host, port, path, and query components. - Validate Nostr public identifiers as properly encoded `npub` values or fixed-length hexadecimal public keys. - Explicitly reject shell metacharacters, control characters, whitespace-based argument injection, command substitutions, and embedded quotes. - Prefer a PTY library or process API that launches `nak` with an argument array rather than a shell command string. - If `script -c` is unavoidable, apply robust shell escaping independently to every dynamic argument after semantic validation. - Keep trusted default relay values separate from user-provided values and never treat a complete user-provided string as multiple command arguments. - Add negative tests using values containing separators, substitutions, quotes, newlines, and option-like prefixes to confirm that they cannot alter command structure. ]]>
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
Findings (1)

Missing User Warnings

Medium
Confidence
95% confidence
Finding
The skill explicitly instructs users to supply an `nsec` or hex private key directly on the command line via `--sec` without any warning about secret handling. Command-line secrets are commonly exposed through shell history, process listings, logs, transcripts, or agent output, making credential compromise more likely in an agent/PTY-based workflow.

Static analysis

No suspicious patterns detected.