From 84d9ed6655871297e414a4a93248f96327b749d9 Mon Sep 17 00:00:00 2001 From: justcool393 Date: Sun, 13 Nov 2022 21:48:52 -0600 Subject: [PATCH] antispam: sanity check --- files/helpers/actions.py | 18 ++++++++++++++++++ files/routes/comments.py | 1 + files/routes/static.py | 7 +------ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/files/helpers/actions.py b/files/helpers/actions.py index a87638575..681674ebf 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -385,6 +385,24 @@ def execute_blackjack(v, target, body, type): return False return True +def execute_antispam_duplicate_comment_check(v:User, body_html:str): + ''' + Sanity check for newfriends + ''' + if v.id in ANTISPAM_BYPASS_IDS or v.admin_level: return + if v.age >= NOTIFICATION_SPAM_AGE_THRESHOLD: return + if len(body_html) < 16: return + if body_html == '!wordle': return # wordle + compare_time = int(time.time()) - 60 * 60 * 24 + comment = g.db.query(Comment.id).filter(Comment.body_html == body_html, + Comment.created_utc >= compare_time).first() + if not comment: return + v.ban(reason="Spamming.", days=0.0) + send_repeatable_notification(v.id, "Your account has been banned **permanently** for the following reason:\n\n> Too much spam!") + g.db.add(v) + g.db.commit() + abort(403, "Too much spam!") + def execute_antispam_comment_check(body:str, v:User): if v.id in ANTISPAM_BYPASS_IDS: return if len(body) <= COMMENT_SPAM_LENGTH_THRESHOLD: return diff --git a/files/routes/comments.py b/files/routes/comments.py index 0320c6b26..28d346567 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -217,6 +217,7 @@ def comment(v): or (SITE == 'pcmemes.net' and v.id == SNAPPY_ID)) execute_antispam_comment_check(body, v) + execute_antispam_duplicate_comment_check(v, body_html) if len(body_html) > COMMENT_BODY_HTML_LENGTH_LIMIT: abort(400) diff --git a/files/routes/static.py b/files/routes/static.py index fdcf7d6fb..f24da93c3 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -218,12 +218,7 @@ def submit_contact(v): body = body.strip() body_html = sanitize(body) - existing = g.db.query(Comment.id).filter(Comment.author_id == v.id, - Comment.parent_submission == None, - Comment.level == 1, - Comment.sentto == 2, - Comment.body_html == body_html).first() - if existing: abort(409, f"You already sent that message") + execute_antispam_duplicate_comment_check(v, body_html) new_comment = Comment(author_id=v.id, parent_submission=None,