Nostr::Event#verify_signature in the nostr gem only validates the signature over the event's claimed id; it never recomputes the id from the serialized body. A genuine (id, sig, pubkey) triple lifted from any public event can therefore be replayed with injected tags, kind or content and still pass verification.
For POST /users/nostr_login this is an account takeover: an attacker injects their own challenge tag into someone else's signed event and signs in as that key's owner. POST /settings/set_nostr_pubkey is affected the same way.
This adds NostrManager::VerifySignedEvent, which recomputes the id as Digest::SHA256.hexdigest(JSON.dump(event.serialize)) and rejects any mismatch, and uses it in both flows. It also makes VerifyAuth assert kind == 22242 (previously only the tag contents were checked).
Regression tests: a forged body with a valid id/sig pair now fails verification at the service level and returns 422/401 at the endpoints. Full suite green (406 examples, 0 failures).
`Nostr::Event#verify_signature` in the `nostr` gem only validates the signature over the event's claimed `id`; it never recomputes the id from the serialized body. A genuine `(id, sig, pubkey)` triple lifted from any public event can therefore be replayed with injected tags, kind or content and still pass verification.
For `POST /users/nostr_login` this is an account takeover: an attacker injects their own `challenge` tag into someone else's signed event and signs in as that key's owner. `POST /settings/set_nostr_pubkey` is affected the same way.
This adds `NostrManager::VerifySignedEvent`, which recomputes the id as `Digest::SHA256.hexdigest(JSON.dump(event.serialize))` and rejects any mismatch, and uses it in both flows. It also makes `VerifyAuth` assert `kind == 22242` (previously only the tag contents were checked).
Regression tests: a forged body with a valid id/sig pair now fails verification at the service level and returns 422/401 at the endpoints. Full suite green (406 examples, 0 failures).
Found while working on #248.
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.
raucao
added the security label 2026-11-18 16:37:20 +00:00
raucao
merged commit b2e33edc7b into master2026-11-18 16:37:27 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Nostr::Event#verify_signaturein thenostrgem only validates the signature over the event's claimedid; it never recomputes the id from the serialized body. A genuine(id, sig, pubkey)triple lifted from any public event can therefore be replayed with injected tags, kind or content and still pass verification.For
POST /users/nostr_loginthis is an account takeover: an attacker injects their ownchallengetag into someone else's signed event and signs in as that key's owner.POST /settings/set_nostr_pubkeyis affected the same way.This adds
NostrManager::VerifySignedEvent, which recomputes the id asDigest::SHA256.hexdigest(JSON.dump(event.serialize))and rejects any mismatch, and uses it in both flows. It also makesVerifyAuthassertkind == 22242(previously only the tag contents were checked).Regression tests: a forged body with a valid id/sig pair now fails verification at the service level and returns 422/401 at the endpoints. Full suite green (406 examples, 0 failures).
Found while working on #248.