Recompute Nostr event id before trusting signed events #268

Merged
raucao merged 1 commits from bugfix/nostr-event-id-verification into master 2026-11-18 16:37:27 +00:00
1 Commits
Author SHA1 Message Date
raucao 1eccfde70f Recompute Nostr event id before trusting signed events
CI / Test (pull_request) Successful in 44s
Release Drafter / Update release notes draft (pull_request) Successful in 2s
The nostr gem's Event#verify_signature only validates the signature over
the event's claimed id and never recomputes the id from the serialized
body. A genuine (id, sig, pubkey) triple lifted from any public event
could therefore be replayed with injected tags, kind or content and still
pass verification. For Nostr login this allows signing in as the key
owner.

Add NostrManager::VerifySignedEvent, which recomputes the id with
Digest::SHA256.hexdigest(JSON.dump(event.serialize)) and rejects any
mismatch, and use it in the pubkey verification and Nostr login flows.
VerifyAuth now also asserts kind 22242.
2026-11-18 19:51:37 +04:00