Skip to content

Commit ecbb7e6

Browse files
committed
Initial validation of JSON inputs
1 parent a3b917d commit ecbb7e6

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/server/api/user_api.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,16 @@ def user_login_json():
108108
Expects json-encoded form data
109109
"""
110110

111-
post_dict = json.loads(request.data)
112-
username = post_dict["username"]
113-
presentedpw = post_dict["password"]
111+
try:
112+
post_dict = json.loads(request.data)
113+
username = post_dict["username"]
114+
presentedpw = post_dict["password"]
115+
except:
116+
return jsonify("Bad credentials"), 401
117+
118+
if not (isinstance(username, str) and isinstance(presentedpw, str) ):
119+
return jsonify("Bad credentials"), 401 # Don't give us ints, arrays, etc.
120+
114121

115122
with engine.connect() as connection:
116123

0 commit comments

Comments
 (0)