From 7de955ff87499d4f83a7a47060a47c7ecb232851 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 26 Apr 2026 21:55:25 -0500 Subject: [PATCH] Lead with XSS threat model in Nostr security guidance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The single most important thing to understand about a web Nostr client is that nsec keys live in plaintext in localStorage, so any XSS = permanent, unrecoverable key theft. The previous framing led with author filtering (important but lower-stakes) and only mentioned XSS implicitly via URL sanitization. Restructures both the AGENTS.md section and the nostr-security skill so the key-storage reality and XSS mitigations come first, CSP is explained as defense-in-depth (with a walkthrough of the existing index.html policy), and author filtering becomes section 3 — still important, but secondary to script-injection prevention. Also adds a 'no dangerouslySetInnerHTML' rule and a CSP hygiene rule to the top-level checklist so those blockers surface before any sanitization detail. --- .agents/skills/nostr-security/SKILL.md | 380 +++++++++++++++---------- AGENTS.md | 12 +- 2 files changed, 233 insertions(+), 159 deletions(-) diff --git a/.agents/skills/nostr-security/SKILL.md b/.agents/skills/nostr-security/SKILL.md index 9b65185..b0687d0 100644 --- a/.agents/skills/nostr-security/SKILL.md +++ b/.agents/skills/nostr-security/SKILL.md @@ -1,21 +1,230 @@ --- name: nostr-security -description: Secure handling of untrusted Nostr event data — author filtering for trust-sensitive queries (admin actions, moderators, addressable events, NIP-72 communities), URL sanitization before rendering event-sourced links/images, and CSS injection prevention when interpolating event data into styles. Load when building trust-boundary features, rendering user-controlled URLs, or interpolating event data into CSS. +description: Threat model and defenses for a web Nostr client — why XSS is catastrophic when nsec keys live in localStorage, how CSP provides defense-in-depth, URL and CSS sanitization for untrusted event data, and author filtering for trust-sensitive queries (admin actions, moderators, addressable events, NIP-72 communities). Load when building trust-boundary features, rendering user-controlled URLs or markup, interpolating event data into CSS, or reviewing the app's security posture. --- # Nostr Security -Nostr is permissionless: **anyone can publish any event claiming to be anything**. Events carry a cryptographic signature, but the signature only proves *the signer produced this content* — it says nothing about *whether you should trust that signer*. Every security decision in a Nostr client reduces to: **which pubkeys do we trust, and have we filtered our queries accordingly?** +## The threat model you need to internalize -This skill covers three attack surfaces: +**Nostr private keys (`nsec`) are stored in plaintext in `localStorage`.** Any JavaScript running on the page origin can read them with a single line: -1. **Trust-boundary queries** — how to use the `authors` filter so attackers can't forge admin/moderator/owner events. -2. **URL sanitization** — how to handle URLs extracted from event tags, content, or metadata. -3. **CSS injection** — how to safely interpolate event data into `