Limit total actor reactions per post

main
Bob Mottram 2021-11-10 17:35:54 +00:00
parent af69491fe9
commit f36000246d
2 changed files with 9 additions and 2 deletions

View File

@ -35,7 +35,12 @@ from webfinger import webfingerHandle
from auth import createBasicAuthHeader
from posts import getPersonBox
# the maximum number of reactions from individual actors which can be
# added to a post. Hence an adversary can't bombard you with sockpuppet
# generated reactions and make the post infeasibly large
maxActorReactionsPerPost = 64
# regex defining permissable emoji icon range
emojiRegex = re.compile(r'[\u263a-\U0001f645]')
@ -480,6 +485,9 @@ def updateReactionCollection(recentPostsCache: {},
else:
if not obj['reactions'].get('items'):
obj['reactions']['items'] = []
# upper limit for the number of reactions on a post
if len(obj['reactions']['items']) >= maxActorReactionsPerPost:
return
for reactionItem in obj['reactions']['items']:
if reactionItem.get('actor') and reactionItem.get('content'):
if reactionItem['actor'] == actor and \

View File

@ -1304,8 +1304,7 @@ def individualPostAsHtml(signingPrivateKeyPem: str,
if not postJsonObject:
return ''
# maximum number of different emoji reactions which can
# be added to a post
# maximum number of different emoji reactions which can be added to a post
maxReactionTypes = 5
# benchmark