Skip to content

AutoFix PR #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions flask_webgoat/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,22 @@ def login():
username = request.form.get("username")
password = request.form.get("password")
if username is None or password is None:
return (
jsonify({"error": "username and password parameter have to be provided"}),
400,
)
return jsonify({"error": "username and password parameter have to be provided"}), 400

# Generate a secure salt
salt = os.urandom(16)
# Create a key using a KDF
key = base64.urlsafe_b64encode(os.urandom(16))
f = Fernet(key)
# Store the salt and encrypted password in the database
encrypted_password = f.encrypt(password.encode())
query = "INSERT INTO user (username, password, salt) VALUES (?, ?, ?)"
query_db(query, (username, encrypted_password, salt), commit=True)

# vulnerability: SQL Injection
query = (
"SELECT id, username, access_level FROM user WHERE username = '%s' AND password = '%s'"
% (username, password)
)
result = query_db(query, [], True)
if result is None:
return jsonify({"bad_login": True}), 400
session["user_info"] = (result[0], result[1], result[2])
return jsonify({"success": True})



@bp.route("/login_and_redirect")
def login_and_redirect():
username = request.args.get("username")
Expand All @@ -46,3 +45,4 @@ def login_and_redirect():
return redirect(url)
session["user_info"] = (result[0], result[1], result[2])
return jsonify({"success": True})

Loading