Disconnect if bad websocket requests instead of flasks abort

This commit is contained in:
Jeremy Zhang 2018-02-16 19:37:12 +00:00
parent 9e53f16eb2
commit a02b33a3cb
2 changed files with 6 additions and 0 deletions

View File

@ -74,6 +74,8 @@ class Gateway(Namespace):
visitor_mode = data["visitor_mode"] visitor_mode = data["visitor_mode"]
if not visitor_mode: if not visitor_mode:
key = None key = None
if "unauthenticated" not in session:
disconnect()
if session["unauthenticated"]: if session["unauthenticated"]:
key = session["user_keys"][guild_id] key = session["user_keys"][guild_id]
status = update_user_status(guild_id, session["username"], key) status = update_user_status(guild_id, session["username"], key)

View File

@ -3,6 +3,7 @@ import json
from requests_oauthlib import OAuth2Session from requests_oauthlib import OAuth2Session
from flask import session, abort, url_for from flask import session, abort, url_for
from titanembeds.utils import redis_store, make_user_cache_key from titanembeds.utils import redis_store, make_user_cache_key
from flask_socketio import disconnect
authorize_url = "https://discordapp.com/api/oauth2/authorize" authorize_url = "https://discordapp.com/api/oauth2/authorize"
token_url = "https://discordapp.com/api/oauth2/token" token_url = "https://discordapp.com/api/oauth2/token"
@ -49,6 +50,9 @@ def get_user_guilds():
return cache.decode("utf-8") return cache.decode("utf-8")
req = discordrest_from_user("/users/@me/guilds") req = discordrest_from_user("/users/@me/guilds")
if req.status_code != 200: if req.status_code != 200:
if getattr(request, sid):
disconnect()
return
abort(req.status_code) abort(req.status_code)
req = json.dumps(req.json()) req = json.dumps(req.json())
redis_store.set("OAUTH/USERGUILDS/"+str(make_user_cache_key()), req, 250) redis_store.set("OAUTH/USERGUILDS/"+str(make_user_cache_key()), req, 250)