fix(relay): widen gift-wrap created_at drift window to NIP-59's two days - #4324
Open
iroiro147 wants to merge 1 commit into
Open
fix(relay): widen gift-wrap created_at drift window to NIP-59's two days#4324iroiro147 wants to merge 1 commit into
iroiro147 wants to merge 1 commit into
Conversation
Fixes block#4192. NIP-59 instructs clients to randomize a gift wrap's `created_at` into the past — "SHOULD be tweaked to thwart time-analysis attacks" — canonically up to 2 days. `nostr-tools` and other mainstream implementations do this by default. Buzz relay applies the standard ±15-minute freshness window uniformly across kinds, which rejects every spec-following NIP-17 client: the wrap produced by `nostr-tools` `nip17.wrapEvent()` (defaults to backdating) is rejected 100% of the time. The wrap's timestamp is deliberately meaningless; ordering and retention decisions for gift wraps cannot rely on it anyway. The inner seal and rumor timestamps are end-to-end encrypted and order on their own. Change: introduce a `max_timestamp_drift_secs(kind)` helper that returns ±15 minutes for regular kinds and 2 days + 15 minutes skew margin for KIND_GIFT_WRAP, then use it at the freshness check in `ingest_event_inner`. Tests cover both branches of the helper — gift-wrap gets the wide window, non-gift-wrap kinds stay at the tight 15-minute default. `cargo check -p buzz-relay --lib` clean. `cargo test -p buzz-relay --lib --offline` 157/157 pass including the 2 new tests. `cargo fmt --check` clean. Signed-off-by: Sarthak Singh <sarthak.singh@juspay.in>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4192.
NIP-59 instructs clients to randomize a gift wrap's
created_atinto thepast — "The
created_attimestamp SHOULD be tweaked to thwart time-analysis attacks" — canonically up to 2 days.
nostr-toolsand othermainstream implementations do this by default. Buzz relay applies the
standard ±15-minute freshness window uniformly across kinds, which rejects
every spec-following NIP-17 client: wraps produced by
nostr-toolsnip17.wrapEvent()(whose defaults backdate the wrap) are rejected 100%of the time. No conforming NIP-17 client can deliver a private DM through
a Buzz relay.
The wrap's timestamp is deliberately meaningless; ordering and retention
decisions for gift wraps cannot rely on it anyway. The inner seal and
rumor timestamps are end-to-end encrypted and order on their own.
Changes
crates/buzz-relay/src/handlers/ingest.rsmax_timestamp_drift_secs(kind)helper returning ±15 minutes forregular kinds and
2 * 24 * 3600 + 900(2 days + NIP-59 skew margin)for
KIND_GIFT_WRAP.ingest_event_innernow uses the helper at the freshness check insteadof a single constant.
Tests
ingest::tests::gift_wrap_drift_window_is_two_days_plus_skew— assertsmax_timestamp_drift_secs(KIND_GIFT_WRAP) == 2*24*3600 + 900.ingest::tests::non_gift_wrap_drift_window_is_tight_15_minutes— kinds1, 9, and
KIND_LONG_FORMstill get 900.Verification
cargo check -p buzz-relay --lib— clean.cargo test -p buzz-relay --lib --offline— 157/157 pass.cargo fmt -p buzz-relay --check— clean.Out of scope
KIND_GIFT_WRAPalreadyWebSocket-only at :1828) or the per-kind scope allowlist.