Compare commits

...

2 Commits

Author SHA1 Message Date
fiatjaf
7a3eb6fb08 plugins.PreventLargeTags() 2023-11-13 16:26:27 -03:00
fiatjaf
1abeab4851 filter.Limit is zero by default, so we will short-circuit on negative limits. 2023-11-13 10:55:17 -03:00
2 changed files with 15 additions and 1 deletions

View File

@@ -23,6 +23,20 @@ func PreventTooManyIndexableTags(max int) func(context.Context, *nostr.Event) (b
}
}
// PreventLargeTags rejects events that have indexable tag values greater than maxTagValueLen.
func PreventLargeTags(maxTagValueLen int) func(context.Context, *nostr.Event) (bool, string) {
return func(ctx context.Context, event *nostr.Event) (reject bool, msg string) {
for _, tag := range event.Tags {
if len(tag) > 1 && len(tag[0]) == 1 {
if len(tag[1]) > maxTagValueLen {
return true, "event contains too large tags"
}
}
}
return false, ""
}
}
// RestrictToSpecifiedKinds returns a function that can be used as a RejectFilter that will reject
// any events with kinds different than the specified ones.
func RestrictToSpecifiedKinds(kinds ...uint16) func(context.Context, *nostr.Event) (bool, string) {

View File

@@ -16,7 +16,7 @@ func (rl *Relay) handleRequest(ctx context.Context, id string, eose *sync.WaitGr
ovw(ctx, &filter)
}
if filter.Limit == 0 {
if filter.Limit < 0 {
return
}