fix: policies, nip04 check

This commit is contained in:
Amarpreet Minhas 2024-08-15 12:03:51 -04:00
parent b65ce5753a
commit 8f880fdf7f

View file

@ -134,12 +134,12 @@ func NewRelay(version string) *khatru.Relay {
relay.DeleteEvent = append(relay.DeleteEvent, RelayDb.DeleteEvent) relay.DeleteEvent = append(relay.DeleteEvent, RelayDb.DeleteEvent)
// apply policies // apply policies
policies.ApplySaneDefaults(relay) // disabled during backporting
//policies.ApplySaneDefaults(relay)
relay.RejectEvent = append( relay.RejectEvent = append(
relay.RejectEvent, relay.RejectEvent,
RejectUnregisteredNpubs, RejectUnregisteredNpubs,
policies.PreventLargeTags(80),
policies.RejectEventsWithBase64Media, policies.RejectEventsWithBase64Media,
policies.ValidateKind, policies.ValidateKind,
) )
@ -147,9 +147,6 @@ func NewRelay(version string) *khatru.Relay {
relay.RejectFilter = append( relay.RejectFilter = append(
relay.RejectFilter, relay.RejectFilter,
policies.RejectKind04Snoopers, policies.RejectKind04Snoopers,
policies.AntiSyncBots,
policies.NoComplexFilters,
policies.NoEmptyFilters,
) )
return relay return relay
} }
@ -160,11 +157,21 @@ func RejectUnregisteredNpubs(ctx context.Context, event *nostr.Event) (reject bo
// reject nip-04 messages to users who aren't registered // reject nip-04 messages to users who aren't registered
if event.Kind == 4 { if event.Kind == 4 {
receiver := event.Tags.GetFirst([]string{"p"}).Value() receiver := event.Tags.GetFirst([]string{"p"}).Value()
var uid int var rid int
err := DB.QueryRow("SELECT id FROM users WHERE pubkey=$1", receiver).Scan(&uid) err := DB.QueryRow("SELECT id FROM users WHERE pubkey=$1", receiver).Scan(&rid)
if err != nil { if err != nil {
l.Debug().Msgf("recipient pubkey %s not found: %s", receiver, err.Error()) rid = -1
return true, fmt.Sprintf("recipient pubkey %s is not registered to any users", receiver) }
var sid int
err = DB.QueryRow("SELECT id FROM users WHERE pubkey=$1", event.PubKey).Scan(&sid)
if err != nil {
sid = -1
}
if rid != -1 || sid != -1 {
l.Debug().Msgf("pubkeys %s or %s not found to be registered", receiver, event.PubKey)
return true, fmt.Sprintf("nobody in this nip04 message is registered to the relay")
} }
return false, "" return false, ""
} }