diff --git a/constants.py b/constants.py index a7daa26..88ab9e0 100644 --- a/constants.py +++ b/constants.py @@ -9,8 +9,8 @@ UPLOAD_DIR = "uploads" MINIMUM_COSINE_SIMILARITY = 0.4 WORD_TO_COMPARE = "hand touching grass" DATABASE_FILE = "data.db" -MINIMUM_OCR_SIMILARITY = 0.7 -OCR_CHALLENGE_LENGTH = 1 +MINIMUM_OCR_SIMILARITY = 0.55 +OCR_CHALLENGE_LENGTH = 4 ACHIEVEMENTS = [ [1, "I went outside!", "Brag to your friends with this one! You went outside the first time in your life. Continue on your journey."], diff --git a/main.py b/main.py index 4e6e382..9469dc9 100644 --- a/main.py +++ b/main.py @@ -6,7 +6,7 @@ from PIL import Image from jina import get_grass_touching_similarity from ocr_check import generate_challenge, check_text_similarity -import os, flask_login, uuid, base64, sqlite3, bcrypt, secrets, hashlib, time, threading +import os, flask_login, uuid, base64, sqlite3, bcrypt, secrets, hashlib, time, threading, html if os.path.exists(".env"): load_dotenv(".env") @@ -328,6 +328,11 @@ def register(): elif request.method == "POST": username, password = request.form.get("username"), request.form.get("password") + if username != html.escape(username, quote=True): + return "No XSS please" + + username = html.escape(username, quote=True) + if not challenges.get(username): return Response("Start and finish a challenge before registering.", 401) @@ -356,7 +361,11 @@ def register(): @flask_login.login_required def change_username(): 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() diff --git a/ocr_check.py b/ocr_check.py index 060210e..eb96801 100644 --- a/ocr_check.py +++ b/ocr_check.py @@ -1,8 +1,6 @@ import easyocr, difflib, random, string from constants import OCR_CHALLENGE_LENGTH -from english_words import get_english_words_set -words = list(get_english_words_set(['gcide'], lower=True, alpha=True)) reader = easyocr.Reader(['en']) def check_text_similarity(image_path, text): @@ -12,4 +10,4 @@ def check_text_similarity(image_path, text): return image_text, similarity def generate_challenge(username): - return f"{username} {' '.join([random.choice(words) for _ in range(OCR_CHALLENGE_LENGTH)])}" \ No newline at end of file + return f"{username} {''.join([str(random.randint(0, 10)) for _ in range(OCR_CHALLENGE_LENGTH)])}" \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 9585263..508f5ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,6 @@ readme = "README.md" requires-python = ">=3.11" dependencies = [ "bcrypt>=4.3.0", - "english-words>=2.0.1", "flask>=3.1.1", "flask-login>=0.6.3", "pillow>=11.3.0", diff --git a/requirements.txt b/requirements.txt index dffabe2..fb9e85e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,8 +10,6 @@ charset-normalizer==3.4.3 # via requests click==8.2.1 # via flask -english-words==2.0.1 - # via grass-touching-captcha (pyproject.toml) flask==3.1.1 # via # grass-touching-captcha (pyproject.toml) diff --git a/templates/submit_grass_touching.jinja2 b/templates/submit_grass_touching.jinja2 index 4bc62c8..df34ce4 100644 --- a/templates/submit_grass_touching.jinja2 +++ b/templates/submit_grass_touching.jinja2 @@ -44,7 +44,7 @@