fsd
This commit is contained in:
parent
5d73bb34e8
commit
d833e3916c
8 changed files with 41 additions and 105 deletions
|
@ -805,7 +805,7 @@ approved_embed_hosts = [
|
||||||
|
|
||||||
hosts = "|".join(approved_embed_hosts).replace('.','\.')
|
hosts = "|".join(approved_embed_hosts).replace('.','\.')
|
||||||
|
|
||||||
image_check_regex = re.compile(f'!\[\]\(((?!(https:\/\/([a-z0-9-]+\.)*({hosts})\/|\/images\/)).*?)\)', flags=re.A)
|
image_check_regex = re.compile(f'!\[\]\(((?!(https:\/\/([a-z0-9-]+\.)*({hosts})\/|\/)).*?)\)', flags=re.A)
|
||||||
|
|
||||||
embed_fullmatch_regex = re.compile(f'https:\/\/([a-z0-9-]+\.)*({hosts})\/[\w:~,()\-.#&\/=?@%;+]*', flags=re.A)
|
embed_fullmatch_regex = re.compile(f'https:\/\/([a-z0-9-]+\.)*({hosts})\/[\w:~,()\-.#&\/=?@%;+]*', flags=re.A)
|
||||||
|
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
from flask import *
|
|
||||||
from urllib.parse import urlparse
|
|
||||||
from files.classes import BannedDomain
|
|
||||||
|
|
||||||
def filter_comment_html(html_text):
|
|
||||||
|
|
||||||
soup = BeautifulSoup(html_text, 'lxml')
|
|
||||||
|
|
||||||
links = soup.find_all("a")
|
|
||||||
|
|
||||||
domain_list = set()
|
|
||||||
|
|
||||||
for link in links:
|
|
||||||
|
|
||||||
href = link.get("href")
|
|
||||||
if not href: continue
|
|
||||||
|
|
||||||
url = urlparse(href)
|
|
||||||
domain = url.netloc
|
|
||||||
path = url.path
|
|
||||||
domain_list.add(domain+path)
|
|
||||||
|
|
||||||
parts = domain.split(".")
|
|
||||||
for i in range(len(parts)):
|
|
||||||
new_domain = parts[i]
|
|
||||||
for j in range(i + 1, len(parts)):
|
|
||||||
new_domain += "." + parts[j]
|
|
||||||
domain_list.add(new_domain)
|
|
||||||
|
|
||||||
bans = [x for x in g.db.query(BannedDomain).filter(BannedDomain.domain.in_(list(domain_list))).all()]
|
|
||||||
|
|
||||||
if bans: return bans
|
|
||||||
else: return []
|
|
|
@ -257,6 +257,34 @@ def sanitize(sanitized, alert=False, comment=False, edit=False):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
soup = BeautifulSoup(sanitized, 'lxml')
|
||||||
|
|
||||||
|
links = soup.find_all("a")
|
||||||
|
|
||||||
|
domain_list = set()
|
||||||
|
|
||||||
|
for link in links:
|
||||||
|
|
||||||
|
href = link.get("href")
|
||||||
|
if not href: continue
|
||||||
|
|
||||||
|
url = urlparse(href)
|
||||||
|
domain = url.netloc
|
||||||
|
path = url.path
|
||||||
|
domain_list.add(domain+path)
|
||||||
|
|
||||||
|
parts = domain.split(".")
|
||||||
|
for i in range(len(parts)):
|
||||||
|
new_domain = parts[i]
|
||||||
|
for j in range(i + 1, len(parts)):
|
||||||
|
new_domain += "." + parts[j]
|
||||||
|
domain_list.add(new_domain)
|
||||||
|
|
||||||
|
bans = g.db.query(BannedDomain.domain).filter(BannedDomain.domain.in_(list(domain_list))).all()
|
||||||
|
|
||||||
|
if bans: abort(403, description=f"Remove the banned domains {bans} and try again!")
|
||||||
|
|
||||||
|
|
||||||
signal.alarm(0)
|
signal.alarm(0)
|
||||||
|
|
||||||
return sanitized
|
return sanitized
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from files.helpers.wrappers import *
|
from files.helpers.wrappers import *
|
||||||
from files.helpers.filters import *
|
|
||||||
from files.helpers.alerts import *
|
from files.helpers.alerts import *
|
||||||
from files.helpers.images import *
|
from files.helpers.images import *
|
||||||
from files.helpers.const import *
|
from files.helpers.const import *
|
||||||
|
@ -323,13 +322,6 @@ def api_comment(v):
|
||||||
|
|
||||||
body_html = sanitize(body, comment=True)
|
body_html = sanitize(body, comment=True)
|
||||||
|
|
||||||
bans = filter_comment_html(body_html)
|
|
||||||
|
|
||||||
if bans:
|
|
||||||
ban = bans[0]
|
|
||||||
reason = f"Remove the {ban.domain} link from your comment and try again."
|
|
||||||
if ban.reason: reason += f" {ban.reason}"
|
|
||||||
return {"error": reason}, 401
|
|
||||||
|
|
||||||
if parent_post.id not in ADMIGGERS and '!slots' not in body.lower() and '!blackjack' not in body.lower() and '!wordle' not in body.lower() and AGENDAPOSTER_PHRASE not in body.lower():
|
if parent_post.id not in ADMIGGERS and '!slots' not in body.lower() and '!blackjack' not in body.lower() and '!wordle' not in body.lower() and AGENDAPOSTER_PHRASE not in body.lower():
|
||||||
existing = g.db.query(Comment.id).filter(Comment.author_id == v.id,
|
existing = g.db.query(Comment.id).filter(Comment.author_id == v.id,
|
||||||
|
@ -737,16 +729,6 @@ def edit_comment(cid, v):
|
||||||
|
|
||||||
body_html = sanitize(body, edit=True)
|
body_html = sanitize(body, edit=True)
|
||||||
|
|
||||||
bans = filter_comment_html(body_html)
|
|
||||||
|
|
||||||
if bans:
|
|
||||||
|
|
||||||
ban = bans[0]
|
|
||||||
reason = f"Remove the {ban.domain} link from your comment and try again."
|
|
||||||
|
|
||||||
if ban.reason: reason += f" {ban.reason}"
|
|
||||||
|
|
||||||
return {'error': reason}, 400
|
|
||||||
if '!slots' not in body.lower() and '!blackjack' not in body.lower() and '!wordle' not in body.lower() and AGENDAPOSTER_PHRASE not in body.lower():
|
if '!slots' not in body.lower() and '!blackjack' not in body.lower() and '!wordle' not in body.lower() and AGENDAPOSTER_PHRASE not in body.lower():
|
||||||
now = int(time.time())
|
now = int(time.time())
|
||||||
cutoff = now - 60 * 60 * 24
|
cutoff = now - 60 * 60 * 24
|
||||||
|
|
|
@ -23,8 +23,16 @@ def error_401(e):
|
||||||
|
|
||||||
@app.errorhandler(403)
|
@app.errorhandler(403)
|
||||||
def error_403(e):
|
def error_403(e):
|
||||||
if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "403 Forbidden"}, 403
|
|
||||||
else: return render_template('errors/403.html', err=True), 403
|
description = e.description
|
||||||
|
if description == "You don't have the permission to access the requested resource. It is either read-protected or not readable by the server.": description = ''
|
||||||
|
|
||||||
|
if request.headers.get("Authorization") or request.headers.get("xhr"):
|
||||||
|
if not description: description = "403 Forbidden"
|
||||||
|
return {"error": description}, 403
|
||||||
|
else:
|
||||||
|
if not description: description = "YOU AREN'T WELCOME HERE GO AWAY"
|
||||||
|
return render_template('errors/403.html', description=description, err=True), 403
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(404)
|
@app.errorhandler(404)
|
||||||
|
|
|
@ -3,7 +3,6 @@ import gevent
|
||||||
import requests
|
import requests
|
||||||
from files.helpers.wrappers import *
|
from files.helpers.wrappers import *
|
||||||
from files.helpers.sanitize import *
|
from files.helpers.sanitize import *
|
||||||
from files.helpers.filters import *
|
|
||||||
from files.helpers.alerts import *
|
from files.helpers.alerts import *
|
||||||
from files.helpers.discord import send_discord_message, send_cringetopia_message
|
from files.helpers.discord import send_discord_message, send_cringetopia_message
|
||||||
from files.helpers.const import *
|
from files.helpers.const import *
|
||||||
|
@ -510,14 +509,6 @@ def edit_post(pid, v):
|
||||||
if v.id == p.author_id and v.marseyawarded and marseyaward_body_regex.search(body_html):
|
if v.id == p.author_id and v.marseyawarded and marseyaward_body_regex.search(body_html):
|
||||||
return {"error":"You can only type marseys!"}, 403
|
return {"error":"You can only type marseys!"}, 403
|
||||||
|
|
||||||
bans = filter_comment_html(body_html)
|
|
||||||
if bans:
|
|
||||||
ban = bans[0]
|
|
||||||
reason = f"Remove the {ban.domain} link from your post and try again."
|
|
||||||
if ban.reason:
|
|
||||||
reason += f" {ban.reason}"
|
|
||||||
|
|
||||||
return {"error": reason}, 403
|
|
||||||
|
|
||||||
p.body = body
|
p.body = body
|
||||||
|
|
||||||
|
@ -1110,12 +1101,7 @@ def submit_post(v, sub=None):
|
||||||
|
|
||||||
if len(body_html) > 40000: return error("Submission body_html too long! (max 40k characters)")
|
if len(body_html) > 40000: return error("Submission body_html too long! (max 40k characters)")
|
||||||
|
|
||||||
bans = filter_comment_html(body_html)
|
|
||||||
if bans:
|
|
||||||
ban = bans[0]
|
|
||||||
reason = f"Remove the {ban.domain} link from your post and try again."
|
|
||||||
if ban.reason: reason += f" {ban.reason}"
|
|
||||||
return error(reason)
|
|
||||||
|
|
||||||
if request.host == 'rdrama.net' and v.admin_level < 2: club = False
|
if request.host == 'rdrama.net' and v.admin_level < 2: club = False
|
||||||
else: club = bool(request.values.get("club",""))
|
else: club = bool(request.values.get("club",""))
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from files.helpers.alerts import *
|
from files.helpers.alerts import *
|
||||||
from files.helpers.sanitize import *
|
from files.helpers.sanitize import *
|
||||||
from files.helpers.filters import filter_comment_html
|
|
||||||
from files.helpers.discord import remove_user, set_nick
|
from files.helpers.discord import remove_user, set_nick
|
||||||
from files.helpers.const import *
|
from files.helpers.const import *
|
||||||
from files.mail import *
|
from files.mail import *
|
||||||
|
@ -141,16 +140,6 @@ def settings_profile_post(v):
|
||||||
sig = image_regex.sub(r'', sig)
|
sig = image_regex.sub(r'', sig)
|
||||||
|
|
||||||
sig_html = sanitize(sig)
|
sig_html = sanitize(sig)
|
||||||
bans = filter_comment_html(sig_html)
|
|
||||||
|
|
||||||
|
|
||||||
if bans:
|
|
||||||
ban = bans[0]
|
|
||||||
reason = f"Remove the {ban.domain} link from your sig and try again."
|
|
||||||
if ban.reason:
|
|
||||||
reason += f" {ban.reason}"
|
|
||||||
|
|
||||||
return {"error": reason}, 401
|
|
||||||
|
|
||||||
if len(sig_html) > 1000:
|
if len(sig_html) > 1000:
|
||||||
return render_template("settings_profile.html",
|
return render_template("settings_profile.html",
|
||||||
|
@ -174,13 +163,6 @@ def settings_profile_post(v):
|
||||||
friends = image_regex.sub(r'', friends)
|
friends = image_regex.sub(r'', friends)
|
||||||
|
|
||||||
friends_html = sanitize(friends)
|
friends_html = sanitize(friends)
|
||||||
bans = filter_comment_html(friends_html)
|
|
||||||
|
|
||||||
if bans:
|
|
||||||
ban = bans[0]
|
|
||||||
reason = f"Remove the {ban.domain} link from your friends list and try again."
|
|
||||||
if ban.reason: reason += f" {ban.reason}"
|
|
||||||
return {"error": reason}, 401
|
|
||||||
|
|
||||||
if len(friends_html) > 2000:
|
if len(friends_html) > 2000:
|
||||||
return render_template("settings_profile.html",
|
return render_template("settings_profile.html",
|
||||||
|
@ -210,13 +192,6 @@ def settings_profile_post(v):
|
||||||
enemies = image_regex.sub(r'', enemies)
|
enemies = image_regex.sub(r'', enemies)
|
||||||
|
|
||||||
enemies_html = sanitize(enemies)
|
enemies_html = sanitize(enemies)
|
||||||
bans = filter_comment_html(enemies_html)
|
|
||||||
|
|
||||||
if bans:
|
|
||||||
ban = bans[0]
|
|
||||||
reason = f"Remove the {ban.domain} link from your enemies list and try again."
|
|
||||||
if ban.reason: reason += f" {ban.reason}"
|
|
||||||
return {"error": reason}, 401
|
|
||||||
|
|
||||||
if len(enemies_html) > 2000:
|
if len(enemies_html) > 2000:
|
||||||
return render_template("settings_profile.html",
|
return render_template("settings_profile.html",
|
||||||
|
@ -266,21 +241,12 @@ def settings_profile_post(v):
|
||||||
return render_template("settings_profile.html", v=v, error="Image/Video files only."), 400
|
return render_template("settings_profile.html", v=v, error="Image/Video files only."), 400
|
||||||
|
|
||||||
bio_html = sanitize(bio)
|
bio_html = sanitize(bio)
|
||||||
bans = filter_comment_html(bio_html)
|
|
||||||
|
|
||||||
if len(bio_html) > 10000:
|
if len(bio_html) > 10000:
|
||||||
return render_template("settings_profile.html",
|
return render_template("settings_profile.html",
|
||||||
v=v,
|
v=v,
|
||||||
error="Your bio is too long")
|
error="Your bio is too long")
|
||||||
|
|
||||||
if bans:
|
|
||||||
ban = bans[0]
|
|
||||||
reason = f"Remove the {ban.domain} link from your bio and try again."
|
|
||||||
if ban.reason:
|
|
||||||
reason += f" {ban.reason}"
|
|
||||||
|
|
||||||
return {"error": reason}, 401
|
|
||||||
|
|
||||||
if len(bio_html) > 10000: abort(400)
|
if len(bio_html) > 10000: abort(400)
|
||||||
|
|
||||||
v.bio = bio[:1500]
|
v.bio = bio[:1500]
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<img alt=":#marseytroll:" loading="lazy" src="/e/marseytroll.webp">
|
<img alt=":#marseytroll:" loading="lazy" src="/e/marseytroll.webp">
|
||||||
<pre></pre>
|
<pre></pre>
|
||||||
<h1 class="h5">403 Forbidden</h1>
|
<h1 class="h5">403 Forbidden</h1>
|
||||||
<p class="text-muted mb-5">YOU AREN'T WELCOME HERE GO AWAY</p>
|
<p class="text-muted mb-5">{{description}}</p>
|
||||||
<div><a href="/" class="btn btn-primary">Go to frontpage</a></div>
|
<div><a href="/" class="btn btn-primary">Go to frontpage</a></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue