Check that linked data context exists for inbox items

merge-requests/30/head
Bob Mottram 2021-01-10 14:05:07 +00:00
parent c807dc075c
commit 0ec3e1ea72
2 changed files with 16 additions and 2 deletions

View File

@ -25,12 +25,12 @@ def hasValidContext(postJsonObject: {}) -> bool:
if not isinstance(url, str): if not isinstance(url, str):
continue continue
if url not in validContexts: if url not in validContexts:
print('Invalid @context: ' + url) print('Unrecognized @context: ' + url)
return False return False
elif isinstance(postJsonObject['@context'], str): elif isinstance(postJsonObject['@context'], str):
url = postJsonObject['@context'] url = postJsonObject['@context']
if url not in validContexts: if url not in validContexts:
print('Invalid @context: ' + url) print('Unrecognized @context: ' + url)
return False return False
else: else:
# not a list or string # not a list or string

View File

@ -248,6 +248,7 @@ from newsdaemon import runNewswireDaemon
from filters import isFiltered from filters import isFiltered
from filters import addGlobalFilter from filters import addGlobalFilter
from filters import removeGlobalFilter from filters import removeGlobalFilter
from context import hasValidContext
import os import os
@ -1040,6 +1041,14 @@ class PubServer(BaseHTTPRequestHandler):
self.server.POSTbusy = False self.server.POSTbusy = False
return 2 return 2
# check that the incoming message has a fully recognized
# linked data context
if not hasValidContext(messageJson):
print('Message arriving at inbox queue has no valid context')
self._400()
self.server.POSTbusy = False
return 3
# check for blocked domains so that they can be rejected early # check for blocked domains so that they can be rejected early
messageDomain = None messageDomain = None
if messageJson.get('actor'): if messageJson.get('actor'):
@ -1050,6 +1059,11 @@ class PubServer(BaseHTTPRequestHandler):
self._400() self._400()
self.server.POSTbusy = False self.server.POSTbusy = False
return 3 return 3
else:
print('Message arriving at inbox queue has no actor')
self._400()
self.server.POSTbusy = False
return 3
# if the inbox queue is full then return a busy code # if the inbox queue is full then return a busy code
if len(self.server.inboxQueue) >= self.server.maxQueueLength: if len(self.server.inboxQueue) >= self.server.maxQueueLength: