88from django .shortcuts import get_object_or_404 , redirect
99from django .template .loader import render_to_string
1010from django .utils .decorators import method_decorator
11+ from django .utils .http import url_has_allowed_host_and_scheme
1112from django .utils .translation import gettext_lazy as _ , get_language
1213from django .utils .text import format_lazy
1314from django .views .decorators .clickjacking import xframe_options_exempt
@@ -62,8 +63,10 @@ def post(self, request, *args, **kwargs):
6263 SubmissionTagging .objects .create (submission = submission , tag = subtag )
6364
6465 # Redirect back to the previous page
65- return redirect (request .headers .get ('referer' , '/' ))
66-
66+ next_url = request .POST .get ('next' )
67+ if next_url and url_has_allowed_host_and_scheme (next_url , allowed_hosts = None ):
68+ return redirect (next_url )
69+ return redirect ('/' )
6770
6871class SubmissionTaggingRemoveView (CourseInstanceBaseView ):
6972 access_mode = ACCESS .ASSISTANT
@@ -80,7 +83,10 @@ def post(self, request, *args, **kwargs):
8083 SubmissionTagging .objects .filter (submission = submission , tag = subtag ).delete ()
8184
8285 # Redirect back to the previous page
83- return redirect (request .headers .get ('referer' , '/' ))
86+ next_url = request .POST .get ('next' )
87+ if next_url and url_has_allowed_host_and_scheme (next_url , allowed_hosts = None ):
88+ return redirect (next_url )
89+ return redirect ('/' )
8490
8591
8692class ExerciseInfoView (ExerciseBaseView ):
0 commit comments