Check for malformed ciphertext within incoming posts

main
Bob Mottram 2021-10-28 12:48:05 +01:00
parent 3024bd77d3
commit 6f2b02f369
2 changed files with 17 additions and 1 deletions

View File

@ -237,6 +237,7 @@ from categories import updateHashtagCategories
from languages import getActorLanguages
from languages import setActorLanguages
from like import updateLikesCollection
from utils import malformedCiphertext
from utils import hasActor
from utils import setReplyIntervalHours
from utils import canReplyTo
@ -1490,10 +1491,15 @@ class PubServer(BaseHTTPRequestHandler):
# save the json for later queue processing
messageBytesDecoded = messageBytes.decode('utf-8')
if malformedCiphertext(messageBytesDecoded):
print('WARN: post contains malformed ciphertext ' +
str(originalMessageJson))
return 4
if containsInvalidLocalLinks(messageBytesDecoded):
print('WARN: post contains invalid local links ' +
str(originalMessageJson))
return 4
return 5
self.server.blockedCacheLastUpdated = \
updateBlockedCache(self.server.baseDir,

View File

@ -2537,6 +2537,16 @@ def isPGPEncrypted(content: str) -> bool:
return False
def malformedCiphertext(content: str) -> bool:
"""Returns true if the given content contains a malformed key
"""
if '----BEGIN ' in content or '----END ' in content:
if not containsPGPPublicKey(content) and \
not isPGPEncrypted(content):
return True
return False
def loadTranslationsFromFile(baseDir: str, language: str) -> ({}, str):
"""Returns the translations dictionary
"""