Skip to content

sdk: bind verification cache entries to signatures - #1508

Merged
yukibtc merged 1 commit into
nostrdevkit:masterfrom
erskingardner:codex/verify-cached-signatures
Nov 3, 2026
Merged

yukibtc merged 1 commit into
nostrdevkit:masterfrom
erskingardner:codex/verify-cached-signatures

Conversation

@erskingardner

Copy link
Copy Markdown
Contributor

Problem

The verification cache skips signature verification for any event with a cached ID, but event IDs do not cover signatures. A relay can therefore send authentic event contents with an invalid signature and have that copy accepted, potentially leaving applications with a stored or delivered event that fails later verification.

Fix

Cache the verified signature alongside each event ID and skip verification only when both match. Verify a different signature before replacing the cache entry, so alternative valid Schnorr signatures remain accepted and invalid signatures leave the verified entry intact.

Validation

  • Reproduced the cache-hit bypass with a regression test against unchanged upstream code.
  • Added coverage for invalid signatures on cache misses and hits, preservation of verified entries, and replacement by alternative valid signatures.
  • cargo test -p nostr-sdk --lib shared::tests
  • just precommit

Only skip signature verification when both the event ID and signature match a previously verified event. Reverify different signatures before replacing the entry so valid alternative signatures remain accepted.

Add regression coverage for invalid signatures on cache misses and hits, cache preservation, and alternative valid signatures.
@codecov

codecov Bot commented Nov 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@yukibtc
yukibtc merged commit a991ff0 into nostrdevkit:master Nov 3, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants