Not 500 error when given invalid guild id or css id in embed page

This commit is contained in:
Jeremy Zhang 2018-03-28 04:51:05 +00:00
parent 46926cd93c
commit e8d37a791c
2 changed files with 11 additions and 2 deletions

View File

@ -1,6 +1,6 @@
from flask import Blueprint, render_template, abort, redirect, url_for, session, request from flask import Blueprint, render_template, abort, redirect, url_for, session, request
from flask_babel import gettext from flask_babel import gettext
from titanembeds.utils import check_guild_existance, guild_query_unauth_users_bool, guild_accepts_visitors, guild_unauthcaptcha_enabled from titanembeds.utils import check_guild_existance, guild_query_unauth_users_bool, guild_accepts_visitors, guild_unauthcaptcha_enabled, is_int
from titanembeds.oauth import generate_guild_icon_url, generate_avatar_url from titanembeds.oauth import generate_guild_icon_url, generate_avatar_url
from titanembeds.database import db, Guilds, UserCSS, list_disabled_guilds from titanembeds.database import db, Guilds, UserCSS, list_disabled_guilds
from config import config from config import config
@ -25,6 +25,8 @@ def get_logingreeting():
def get_custom_css(): def get_custom_css():
css = request.args.get("css", None) css = request.args.get("css", None)
if not is_int(css):
css = None
if css: if css:
css = db.session.query(UserCSS).filter(UserCSS.id == css).first() css = db.session.query(UserCSS).filter(UserCSS.id == css).first()
return css return css
@ -59,7 +61,7 @@ def parse_url_domain(url):
return parsed.netloc return parsed.netloc
return url return url
@embed.route("/<string:guild_id>") @embed.route("/<int:guild_id>")
def guild_embed(guild_id): def guild_embed(guild_id):
if check_guild_existance(guild_id): if check_guild_existance(guild_id):
guild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first() guild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first()

View File

@ -322,6 +322,13 @@ def language_code_list():
codes.append(lang["code"]) codes.append(lang["code"])
return codes return codes
def is_int(specimen):
try:
int(specimen)
return True
except:
return False
rate_limiter = Limiter(key_func=get_client_ipaddr) # Default limit by ip address rate_limiter = Limiter(key_func=get_client_ipaddr) # Default limit by ip address
socketio = SocketIO(engineio_logger=config.get("engineio-logging", False)) socketio = SocketIO(engineio_logger=config.get("engineio-logging", False))
babel = Babel() babel = Babel()