mirror of
https://github.com/csd4ni3l/debt-by-ai.git
synced 2025-11-05 04:57:56 +01:00
fix XSS
This commit is contained in:
20
app.py
20
app.py
@@ -4,7 +4,7 @@ from google.genai import Client, types
|
|||||||
|
|
||||||
from constants import *
|
from constants import *
|
||||||
|
|
||||||
import os, requests, time, re, sqlite3, flask_login, bcrypt, secrets
|
import os, requests, time, re, sqlite3, flask_login, bcrypt, secrets, html
|
||||||
|
|
||||||
if os.path.exists(".env"):
|
if os.path.exists(".env"):
|
||||||
load_dotenv(".env")
|
load_dotenv(".env")
|
||||||
@@ -115,7 +115,7 @@ def profile_external(username):
|
|||||||
|
|
||||||
row = cur.fetchone()
|
row = cur.fetchone()
|
||||||
if not row:
|
if not row:
|
||||||
return Response("Invalid login. Please log out.", 400)
|
return Response("Invalid user.", 400)
|
||||||
|
|
||||||
cur.close()
|
cur.close()
|
||||||
|
|
||||||
@@ -227,13 +227,19 @@ def register():
|
|||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
return render_template("register.jinja2")
|
return render_template("register.jinja2")
|
||||||
elif request.method == "POST":
|
elif request.method == "POST":
|
||||||
username, password = request.form.get("username"), request.form.get("password")
|
password = request.form.get("password")
|
||||||
|
|
||||||
|
if request.form["username"] != html.escape(request.form["username"], quote=True):
|
||||||
|
return "No XSS please"
|
||||||
|
|
||||||
|
username = html.escape(request.form["username"], quote=True)
|
||||||
|
|
||||||
cur = get_db().cursor()
|
cur = get_db().cursor()
|
||||||
|
|
||||||
cur.execute("SELECT username from Users WHERE username = ?", (username,))
|
cur.execute("SELECT username from Users WHERE username = ?", (username,))
|
||||||
|
|
||||||
if cur.fetchone():
|
if cur.fetchone():
|
||||||
|
cur.close()
|
||||||
return Response("An account with this username already exists.", 400)
|
return Response("An account with this username already exists.", 400)
|
||||||
|
|
||||||
salt = bcrypt.gensalt()
|
salt = bcrypt.gensalt()
|
||||||
@@ -358,7 +364,11 @@ def ai_answer():
|
|||||||
@flask_login.login_required
|
@flask_login.login_required
|
||||||
def change_username():
|
def change_username():
|
||||||
username = flask_login.current_user.id
|
username = flask_login.current_user.id
|
||||||
new_username = request.form["new_username"]
|
|
||||||
|
if request.form["new_username"] != html.escape(request.form["new_username"], quote=True):
|
||||||
|
return "No XSS please"
|
||||||
|
|
||||||
|
new_username = html.escape(request.form["new_username"], quote=True)
|
||||||
|
|
||||||
cur = get_db().cursor()
|
cur = get_db().cursor()
|
||||||
|
|
||||||
@@ -406,7 +416,7 @@ def change_password():
|
|||||||
|
|
||||||
@app.route("/delete_account", methods=["POST"])
|
@app.route("/delete_account", methods=["POST"])
|
||||||
@flask_login.login_required
|
@flask_login.login_required
|
||||||
def delete_accocunt():
|
def delete_account():
|
||||||
username = flask_login.current_user.id
|
username = flask_login.current_user.id
|
||||||
|
|
||||||
cur = get_db().cursor()
|
cur = get_db().cursor()
|
||||||
|
|||||||
Reference in New Issue
Block a user