Merge branch 'main' of gitlab.com:bashrc2/epicyon

merge-requests/30/head
Bob Mottram 2021-10-26 17:36:19 +01:00
commit 90f607751a
3 changed files with 31 additions and 1 deletions

View File

@ -1184,3 +1184,25 @@ def wordsSimilarity(content1: str, content2: str, minWords: int) -> int:
else:
diff += abs(histogram2[combinedWords] - histogram1[combinedWords])
return 100 - int(diff * 100 / len(histogram1.items()))
def containsInvalidLocalLinks(content: str) -> bool:
"""Returns true if the given content has invalid links
"""
invalidStrings = (
'mute', 'unmute', 'editeventpost', 'notifypost',
'delete', 'options', 'page', 'repeat',
'bm', 'tl', 'actor', 'unrepeat',
'unannounce', 'like', 'unlike', 'bookmark',
'unbookmark', 'likedBy', 'id', 'time',
'year', 'month', 'day', 'editnewpost',
'graph', 'showshare', 'category', 'showwanted',
'rmshare', 'rmwanted', 'repeatprivate',
'unrepeatprivate', 'replyto',
'replyfollowers', 'replydm', 'editblogpost',
'handle', 'blockdomain'
)
for invStr in invalidStrings:
if '/?' + invStr + '=' in content:
return True
return False

View File

@ -11,7 +11,9 @@
"thetimes.co.uk",
"thesundaytimes.co.uk",
"pressassociation.com",
"news.co.uk",
"/news.co.uk",
".news.co.uk",
" news.co.uk",
"newscorpaustralia.com",
"theaustralian.com.au",
"aap.com.au",

View File

@ -299,6 +299,7 @@ from utils import hasGroupType
from manualapprove import manualDenyFollowRequestThread
from manualapprove import manualApproveFollowRequestThread
from announce import createAnnounce
from content import containsInvalidLocalLinks
from content import getPriceFromString
from content import replaceEmojiFromTags
from content import addHtmlTags
@ -1489,6 +1490,11 @@ class PubServer(BaseHTTPRequestHandler):
# save the json for later queue processing
messageBytesDecoded = messageBytes.decode('utf-8')
if containsInvalidLocalLinks(messageBytesDecoded):
print('WARN: post contains invalid local links ' +
str(originalMessageJson))
return 4
self.server.blockedCacheLastUpdated = \
updateBlockedCache(self.server.baseDir,
self.server.blockedCache,