-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allocation logic fix #97
base: main
Are you sure you want to change the base?
Conversation
UnregisteredStudent.objects.filter(email__iexact=student.email).delete() | ||
text = "Allocation Form filled Successfully" | ||
request.session["text"] = text | ||
return redirect(request.path) |
Check warning
Code scanning / CodeQL
URL redirection from remote source Medium
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 7 days ago
To fix the problem, we need to ensure that the redirection URL is validated before it is used. Since request.path
is intended to redirect the user back to the same page, we can use Django's url_has_allowed_host_and_scheme
function to validate the URL. This function checks that the URL is safe to redirect to by ensuring it does not contain an explicit host name and is within the allowed hosts.
We will modify the code to validate request.path
before using it in the redirect. If the validation fails, we will redirect the user to a safe default URL (e.g., the home page).
-
Copy modified lines R8-R9 -
Copy modified lines R412-R415
@@ -7,3 +7,4 @@ | ||
from django.http import JsonResponse | ||
from django.shortcuts import redirect, render | ||
from django.shortcuts import redirect, render | ||
from django.utils.http import url_has_allowed_host_and_scheme | ||
from django.utils.dateparse import parse_date | ||
@@ -410,3 +411,6 @@ | ||
request.session["text"] = text | ||
return redirect(request.path) | ||
if url_has_allowed_host_and_scheme(request.path, allowed_hosts=None): | ||
return redirect(request.path) | ||
else: | ||
return redirect('/') | ||
else: |
No description provided.