diff --git a/api_views/users.py b/api_views/users.py index 172540a..c985509 100644 --- a/api_views/users.py +++ b/api_views/users.py @@ -98,16 +98,12 @@ def login_user(): 'auth_token': auth_token } return Response(json.dumps(responseObject), 200, mimetype="application/json") - if vuln: # Password Enumeration - if user and request_data.get('password') != user.password: - return Response(error_message_helper("Password is not correct for the given username."), 200, - mimetype="application/json") - elif not user: # User enumeration - return Response(error_message_helper("Username does not exist"), 200, mimetype="application/json") - else: - if (user and request_data.get('password') != user.password) or (not user): - return Response(error_message_helper("Username or Password Incorrect!"), 200, - mimetype="application/json") + # Always return a single, generic failure message regardless of whether the + # username exists or the password was wrong, so a caller cannot use the + # response to enumerate valid usernames or confirm passwords via an oracle. + if (user and request_data.get('password') != user.password) or (not user): + return Response(error_message_helper("Username or Password Incorrect!"), 200, + mimetype="application/json") except jsonschema.exceptions.ValidationError as exc: return Response(error_message_helper(exc.message), 400, mimetype="application/json") except: