Skip to content

Commit

Permalink
Fix code scanning alert no. 102: URL redirection from remote source
Browse files Browse the repository at this point in the history
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 00be32f commit 128dcdd
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions routes/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@ 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:
case True:
# 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:
Expand Down Expand Up @@ -178,6 +182,6 @@ def login(direct):
)
case False:
return (
redirect(direct),
redirect(direct), # Safe redirect after validation
301,
)

0 comments on commit 128dcdd

Please sign in to comment.