From 5f65c5a9f45fddc81bce45b4f419aa416b296aa8 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 8 Nov 2022 15:26:06 -0400 Subject: [PATCH] fix: limit the number of content filters in query --- waku/v2/protocol/store/waku_store.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/waku/v2/protocol/store/waku_store.go b/waku/v2/protocol/store/waku_store.go index a38178cc..fa1488a7 100644 --- a/waku/v2/protocol/store/waku_store.go +++ b/waku/v2/protocol/store/waku_store.go @@ -30,10 +30,17 @@ const StoreID_v20beta4 = libp2pProtocol.ID("/vac/waku/store/2.0.0-beta4") // MaxPageSize is the maximum number of waku messages to return per page const MaxPageSize = 100 +// MaxContentFilters is the maximum number of allowed content filters in a query +const MaxContentFilters = 10 + // MaxTimeVariance is the maximum duration in the future allowed for a message timestamp const MaxTimeVariance = time.Duration(20) * time.Second var ( + // ErrMaxContentFilters is returned when the number of content topics in the query + // exceeds the limit + ErrMaxContentFilters = errors.New("exceeds the maximum number of content filters allowed") + // ErrNoPeersAvailable is returned when there are no store peers in the peer store // that could be used to retrieve message history ErrNoPeersAvailable = errors.New("no suitable remote peers") @@ -62,6 +69,10 @@ func findMessages(query *pb.HistoryQuery, msgProvider MessageProvider) ([]*pb.Wa query.PagingInfo.PageSize = MaxPageSize } + if len(query.ContentFilters) > MaxContentFilters { + return nil, nil, ErrMaxContentFilters + } + cursor, queryResult, err := msgProvider.Query(query) if err != nil { return nil, nil, err @@ -436,6 +447,10 @@ func (store *WakuStore) Query(ctx context.Context, query Query, opts ...HistoryR q.ContentFilters = append(q.ContentFilters, &pb.ContentFilter{ContentTopic: cf}) } + if len(q.ContentFilters) > MaxContentFilters { + return nil, ErrMaxContentFilters + } + params := new(HistoryRequestParameters) params.s = store