From 7a3eb6fb0839297fa76076ee1150236bf0f1d7b2 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Mon, 13 Nov 2023 16:26:27 -0300 Subject: [PATCH] plugins.PreventLargeTags() --- plugins/events.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/plugins/events.go b/plugins/events.go index e997891..cb6d80d 100644 --- a/plugins/events.go +++ b/plugins/events.go @@ -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) {