Check that replyTo field is a string

main
Bob Mottram 2020-08-28 15:45:07 +01:00
parent 10a21e797b
commit 41607d1542
4 changed files with 29 additions and 15 deletions

View File

@ -272,6 +272,8 @@ def inboxPermittedMessage(domain: str, messageJson: {},
return False return False
if messageJson['object'].get('inReplyTo'): if messageJson['object'].get('inReplyTo'):
inReplyTo = messageJson['object']['inReplyTo'] inReplyTo = messageJson['object']['inReplyTo']
if not isinstance(inReplyTo, str):
return False
if not urlPermitted(inReplyTo, federationList, "inbox:write"): if not urlPermitted(inReplyTo, federationList, "inbox:write"):
return False return False
@ -1596,6 +1598,8 @@ def populateReplies(baseDir: str, httpPrefix: str, domain: str,
if not messageJson['object'].get('to'): if not messageJson['object'].get('to'):
return False return False
replyTo = messageJson['object']['inReplyTo'] replyTo = messageJson['object']['inReplyTo']
if not isinstance(replyTo, str):
return False
if debug: if debug:
print('DEBUG: post contains a reply') print('DEBUG: post contains a reply')
# is this a reply to a post on this domain? # is this a reply to a post on this domain?
@ -1760,6 +1764,9 @@ def obtainAvatarForReplyPost(session, baseDir: str, httpPrefix: str,
if not lookupActor: if not lookupActor:
return return
if not isinstance(lookupActor, str):
return
if not ('/users/' in lookupActor or if not ('/users/' in lookupActor or
'/accounts/' in lookupActor or '/accounts/' in lookupActor or
'/channel/' in lookupActor or '/channel/' in lookupActor or

View File

@ -388,15 +388,16 @@ def getPosts(session, outboxUrl: str, maxPosts: int,
inReplyTo = '' inReplyTo = ''
if item['object'].get('inReplyTo'): if item['object'].get('inReplyTo'):
if item['object']['inReplyTo']: if item['object']['inReplyTo']:
# No replies to non-permitted domains if isinstance(item['object']['inReplyTo'], str):
if not urlPermitted(item['object']['inReplyTo'], # No replies to non-permitted domains
federationList, if not urlPermitted(item['object']['inReplyTo'],
"objects:read"): federationList,
if debug: "objects:read"):
print('url not permitted ' + if debug:
item['object']['inReplyTo']) print('url not permitted ' +
continue item['object']['inReplyTo'])
inReplyTo = item['object']['inReplyTo'] continue
inReplyTo = item['object']['inReplyTo']
conversation = '' conversation = ''
if item['object'].get('conversation'): if item['object'].get('conversation'):
@ -483,10 +484,11 @@ def getPostDomains(session, outboxUrl: str, maxPosts: int,
if not isinstance(item['object'], dict): if not isinstance(item['object'], dict):
continue continue
if item['object'].get('inReplyTo'): if item['object'].get('inReplyTo'):
postDomain, postPort = \ if isinstance(item['object']['inReplyTo'], str):
getDomainFromActor(item['object']['inReplyTo']) postDomain, postPort = \
if postDomain not in postDomains: getDomainFromActor(item['object']['inReplyTo'])
postDomains.append(postDomain) if postDomain not in postDomains:
postDomains.append(postDomain)
if item['object'].get('tag'): if item['object'].get('tag'):
for tagItem in item['object']['tag']: for tagItem in item['object']['tag']:
@ -2675,8 +2677,9 @@ def isReply(postJsonObject: {}, actor: str) -> bool:
postJsonObject['object']['type'] != 'Article': postJsonObject['object']['type'] != 'Article':
return False return False
if postJsonObject['object'].get('inReplyTo'): if postJsonObject['object'].get('inReplyTo'):
if postJsonObject['object']['inReplyTo'].startswith(actor): if isinstance(postJsonObject['object']['inReplyTo'], str):
return True if postJsonObject['object']['inReplyTo'].startswith(actor):
return True
if not postJsonObject['object'].get('tag'): if not postJsonObject['object'].get('tag'):
return False return False
if not isinstance(postJsonObject['object']['tag'], list): if not isinstance(postJsonObject['object']['tag'], list):

View File

@ -25,6 +25,8 @@ def questionUpdateVotes(baseDir: str, nickname: str, domain: str,
return None return None
if not replyJson['object']['inReplyTo']: if not replyJson['object']['inReplyTo']:
return None return None
if not isinstance(replyJson['object']['inReplyTo'], str):
return None
if not replyJson['object'].get('name'): if not replyJson['object'].get('name'):
return None return None
inReplyTo = replyJson['object']['inReplyTo'] inReplyTo = replyJson['object']['inReplyTo']

View File

@ -473,6 +473,8 @@ def isReplyToBlogPost(baseDir: str, nickname: str, domain: str,
return False return False
if not postJsonObject['object'].get('inReplyTo'): if not postJsonObject['object'].get('inReplyTo'):
return False return False
if not isinstance(postJsonObject['object']['inReplyTo'], str):
return False
blogsIndexFilename = baseDir + '/accounts/' + \ blogsIndexFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/tlblogs.index' nickname + '@' + domain + '/tlblogs.index'
if not os.path.isfile(blogsIndexFilename): if not os.path.isfile(blogsIndexFilename):