fix: policies, nip04 check
This commit is contained in:
parent
b65ce5753a
commit
8f880fdf7f
1 changed files with 16 additions and 9 deletions
|
@ -134,12 +134,12 @@ func NewRelay(version string) *khatru.Relay {
|
|||
relay.DeleteEvent = append(relay.DeleteEvent, RelayDb.DeleteEvent)
|
||||
|
||||
// apply policies
|
||||
policies.ApplySaneDefaults(relay)
|
||||
// disabled during backporting
|
||||
//policies.ApplySaneDefaults(relay)
|
||||
|
||||
relay.RejectEvent = append(
|
||||
relay.RejectEvent,
|
||||
RejectUnregisteredNpubs,
|
||||
policies.PreventLargeTags(80),
|
||||
policies.RejectEventsWithBase64Media,
|
||||
policies.ValidateKind,
|
||||
)
|
||||
|
@ -147,9 +147,6 @@ func NewRelay(version string) *khatru.Relay {
|
|||
relay.RejectFilter = append(
|
||||
relay.RejectFilter,
|
||||
policies.RejectKind04Snoopers,
|
||||
policies.AntiSyncBots,
|
||||
policies.NoComplexFilters,
|
||||
policies.NoEmptyFilters,
|
||||
)
|
||||
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
|
||||
if event.Kind == 4 {
|
||||
receiver := event.Tags.GetFirst([]string{"p"}).Value()
|
||||
var uid int
|
||||
err := DB.QueryRow("SELECT id FROM users WHERE pubkey=$1", receiver).Scan(&uid)
|
||||
var rid int
|
||||
err := DB.QueryRow("SELECT id FROM users WHERE pubkey=$1", receiver).Scan(&rid)
|
||||
if err != nil {
|
||||
l.Debug().Msgf("recipient pubkey %s not found: %s", receiver, err.Error())
|
||||
return true, fmt.Sprintf("recipient pubkey %s is not registered to any users", receiver)
|
||||
rid = -1
|
||||
}
|
||||
|
||||
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, ""
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue