Skip to content

Commit 19cc56e

Browse files
Fix URL redirection from remote source
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent f1d5fd9 commit 19cc56e

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

colander/core/archives/endpoints.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from django.db import transaction
77
from django.http import JsonResponse, HttpResponseRedirect, HttpResponseForbidden, HttpResponse, \
88
StreamingHttpResponse
9-
from django.utils.http import content_disposition_header
9+
from django.utils.http import content_disposition_header, url_has_allowed_host_and_scheme
1010
from rest_framework.exceptions import ValidationError
1111

1212
from colander.core.archives.exporters import schedule_archive_export
@@ -29,7 +29,10 @@ def case_archive_request_view(request, pk):
2929

3030
messages.info(request, "Archive export requested. You will be notified when done.")
3131

32-
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
32+
referrer = request.META.get('HTTP_REFERER')
33+
if referrer and url_has_allowed_host_and_scheme(referrer, allowed_hosts={request.get_host()}):
34+
return HttpResponseRedirect(referrer)
35+
return HttpResponseRedirect('/')
3336

3437

3538
@login_required

0 commit comments

Comments
 (0)