Screen for outgoing abusive posts

merge-requests/30/head
Bob Mottram 2021-02-11 10:33:56 +00:00
parent 2cbcd4eeb2
commit 6806218202
2 changed files with 22 additions and 6 deletions

View File

@ -31,6 +31,7 @@ from session import postImage
from webfinger import webfingerHandle
from httpsig import createSignedHeader
from siteactive import siteIsActive
from utils import removeInvalidCharacters
from utils import fileLastModified
from utils import isPublicPost
from utils import hasUsersPath
@ -823,7 +824,7 @@ def validContentWarning(cw: str) -> str:
# so remove them
if '#' in cw:
cw = cw.replace('#', '').replace(' ', ' ')
return cw
return removeInvalidCharacters(cw)
def _loadAutoCW(baseDir: str, nickname: str, domain: str) -> []:
@ -880,6 +881,8 @@ def _createPostBase(baseDir: str, nickname: str, domain: str, port: int,
eventStatus=None, ticketUrl=None) -> {}:
"""Creates a message
"""
content = removeInvalidCharacters(content)
subject = _addAutoCW(baseDir, nickname, domain, subject, content)
if nickname != 'news':

View File

@ -18,6 +18,13 @@ from followingCalendar import addPersonToCalendar
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
# posts containing these strings will always get screened out,
# both incoming and outgoing.
# Could include dubious clacks or admin dogwhistles
invalidCharacters = (
'', '', '', '', '', ''
)
def getSHA256(msg: str):
"""Returns a SHA256 hash of the given string
@ -514,17 +521,23 @@ def isEvil(domain: str) -> bool:
def containsInvalidChars(jsonStr: str) -> bool:
"""Does the given json string contain invalid characters?
e.g. dubious clacks/admin dogwhistles
"""
invalidStrings = {
'', '', '', '', '', ''
}
for isInvalid in invalidStrings:
for isInvalid in invalidCharacters:
if isInvalid in jsonStr:
return True
return False
def removeInvalidCharacters(text: str) -> str:
"""Removes any invalid characters from a string
"""
for isInvalid in invalidCharacters:
if isInvalid not in text:
continue
text = text.replace(isInvalid, '')
return text
def createPersonDir(nickname: str, domain: str, baseDir: str,
dirname: str) -> str:
"""Create a directory for a person