diff --git a/routes/login.py b/routes/login.py index e3aaa9b..45d9663 100755 --- a/routes/login.py +++ b/routes/login.py @@ -41,7 +41,11 @@ def login(direct): Raises: 401: If the login is unsuccessful. """ - direct = direct.replace("&", "/") # Convert direct link parameter + direct = direct.replace("&", "/").replace('\\', '') # Convert direct link parameter and handle backslashes + from urllib.parse import urlparse # Import urlparse for URL validation + if urlparse(direct).netloc or urlparse(direct).scheme: + # If the direct URL contains a host name or scheme, redirect to home page + direct = '/' match LOG_IN: case True: match "userName" in session: @@ -49,7 +53,7 @@ def login(direct): # If user is already logged in, redirect Log.danger(f'User: "{session["userName"]}" already logged in') return ( - redirect(direct), + redirect(direct), # Safe redirect after validation 301, ) case False: @@ -178,6 +182,6 @@ def login(direct): ) case False: return ( - redirect(direct), + redirect(direct), # Safe redirect after validation 301, )