π‘οΈ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!
Return 400 instead of 500 for passwords over bcrypt's 72-byte limit
Omega (QA)586872e23f1a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1a726c3..364c8cf 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -13,6 +13,8 @@- _Files: `frontend/js/components/tagManager.js`_### Fixed+- **Login/registration/password-change 500 on passwords over 72 bytes fixed:** bcrypt rejects passwords longer than 72 bytes with `ValueError`, which escaped as HTTP 500 on `/api/auth/login` (and latently on register and the password reset/change endpoints for strong long passwords). All four endpoints now check the byte length up front via a new `is_password_too_long()` helper and return HTTP 400. Found by the daily QA sweep.+ - _Files: `backend/auth_routes.py`, `backend/auth_utils.py`- **Insecure direct file access via `/api/files/` fixed (reported by Malik Abdullah):** the legacy `/api/files/<path>` route served any uploaded document to any logged-in user with no ownership check and no regard for the admin's document-sharing (`global_view_enabled`) setting β while `/api/secure-file/` on the same files correctly returned 403. Verified live: with sharing disabled, a second account downloaded another user's invoice via `/api/files/` (200) while `/api/secure-file/` returned 403. Both routes now share a single `_check_file_authorization()` helper (owner, admin, or global-view setting), so they can no longer drift apart; `/api/files/` also gained the path-traversal guard. With sharing enabled (the default, intentional for family/team instances) cross-user access still works consistently on both routes. Credit: reported via responsible disclosure by [humidnhefty](https://github.com/humidnhefty) (Malik Abdullah, Lupine Security).- _Files: `backend/file_routes.py`- **Stored XSS via warranty fields fixed (reported by lazymaster101 and the CSCE 413 Texas A&M team):** warranty cards rendered `product_name`, `vendor`, `model_number`, `warranty_type`, tag names, serial numbers, and the user display name into `innerHTML` without escaping, so a malicious value (e.g. injected through CSV import) executed JavaScript in every viewer's browser. All user-controlled fields are now HTML-escaped before rendering (quotes included, so attribute contexts are safe too), and `product_url` links now also reject `javascript:`/`data:`/`vbscript:` schemes. Verified with live payloads (`<img onerror>`, `<svg onload>`, attribute breakout, `javascript:` URL, malicious tag name) β all render as inert text. Credit: reported via responsible disclosure by [lazymaster101](https://github.com/lazymaster101) and the CSCE 413 (Texas A&M University) vulnerability-research team β Carrigan Royer, Jayani Singh, Seshadithya Saravanan, Aaditya Srinivasan, Miko Quinones.diff --git a/backend/auth_routes.py b/backend/auth_routes.pyindex a574ae3..969afab 100644--- a/backend/auth_routes.py+++ b/backend/auth_routes.py@@ -14,12 +14,12 @@ from psycopg2.extras import Json# Use relative imports for project modulestry:from . import db_handler, notifications- from .auth_utils import generate_token, token_required, is_valid_email, is_valid_password+ from .auth_utils import generate_token, token_required, is_valid_email, is_valid_password, is_password_too_longfrom .localization import SUPPORTED_LANGUAGESexcept ImportError:# Fallback for development environmentimport db_handler, notifications- from auth_utils import generate_token, token_required, is_valid_email, is_valid_password+ from auth_utils import generate_token, token_required, is_valid_email, is_valid_password, is_password_too_longfrom localization import SUPPORTED_LANGUAGES# Import bcrypt from extensions since it's initialized with the app@@ -85,7 +85,11 @@ def register():# Validate password strengthif not is_valid_password(password):return jsonify({'message': 'Password must be at least 8 characters and include uppercase, lowercase, and numbers!'}), 400-++ # bcrypt rejects passwords longer than 72 bytes β fail fast with 400+ if is_password_too_long(password):+ return jsonify({'message': 'Password must not exceed 72 characters!'}), 400+# Hash the passwordpassword_hash = bcrypt.generate_password_hash(password).decode('utf-8')@@ -161,10 +165,14 @@ def login():# Validate required fieldsif not data.get('username') or not data.get('password'):return jsonify({'message': 'Username and password are required!'}), 400-+username = data['username']password = data['password']-++ # bcrypt rejects passwords longer than 72 bytes β fail fast with 400+ if is_password_too_long(password):+ return jsonify({'message': 'Password must not exceed 72 characters!'}), 400+conn = db_handler.get_db_connection()with conn.cursor() as cur:# Check if user exists - include is_admin in the query@@ -655,7 +663,11 @@ def reset_password():# Validate password strengthif not is_valid_password(password):return jsonify({'message': 'Password must be at least 8 characters and include uppercase, lowercase, and numbers!'}), 400-++ # bcrypt rejects passwords longer than 72 bytes β fail fast with 400+ if is_password_too_long(password):+ return jsonify({'message': 'Password must not exceed 72 characters!'}), 400+conn = db_handler.get_db_connection()with conn.cursor() as cur:# Check if token exists and is valid@@ -716,7 +728,11 @@ def change_password():# Validate new password strengthif not is_valid_password(new_password):return jsonify({'message': 'New password must be at least 8 characters and include uppercase, lowercase, and numbers!'}), 400-++ # bcrypt rejects passwords longer than 72 bytes β fail fast with 400+ if is_password_too_long(new_password):+ return jsonify({'message': 'New password must not exceed 72 characters!'}), 400+conn = db_handler.get_db_connection()with conn.cursor() as cur:# Get the user's current password hashdiff --git a/backend/auth_utils.py b/backend/auth_utils.pyindex e5a4510..a7d5aaa 100644--- a/backend/auth_utils.py+++ b/backend/auth_utils.py@@ -136,4 +136,10 @@ def is_valid_password(password):return Falsereturn True++def is_password_too_long(password):+ """bcrypt rejects passwords longer than 72 bytes with ValueError β check+ up front so callers can return 400 instead of surfacing a 500."""+ return len(password.encode('utf-8')) > 72+\ No newline at end of file