diff --git a/posts.py b/posts.py index d64397055..d9695ada9 100644 --- a/posts.py +++ b/posts.py @@ -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': diff --git a/utils.py b/utils.py index 6e9b82e2b..2755cb846 100644 --- a/utils.py +++ b/utils.py @@ -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