Skip to content

Commit 2c8d5df

Browse files
committed
Added dummy pw check to prevent timing diffs
1 parent ecbb7e6 commit 2c8d5df

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/server/api/user_api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,21 @@ def user_login_json():
108108
Expects json-encoded form data
109109
"""
110110

111+
def dummy_check():
112+
"""Perform a fake password hash check to take as much time as a real one."""
113+
pw_bytes = bytes('password', "utf8")
114+
check_password('password', pw_bytes)
115+
111116
try:
112117
post_dict = json.loads(request.data)
113118
username = post_dict["username"]
114119
presentedpw = post_dict["password"]
115120
except:
121+
dummy_check() # Take the same time as with well-formed requests
116122
return jsonify("Bad credentials"), 401
117123

118124
if not (isinstance(username, str) and isinstance(presentedpw, str) ):
125+
dummy_check() # Take the same time as with well-formed requests
119126
return jsonify("Bad credentials"), 401 # Don't give us ints, arrays, etc.
120127

121128

0 commit comments

Comments
 (0)