@@ -105,9 +105,16 @@ def login(request,
105
105
came_from = settings .LOGIN_REDIRECT_URL
106
106
107
107
# Ensure the user-originating redirection url is safe.
108
- if not is_safe_url (url = came_from , allowed_hosts = {request .get_host ()}):
108
+ # By setting SAML_ALLOWED_HOSTS in settings.py the user may provide a list of "allowed"
109
+ # hostnames for post-login redirects, much like one would specify ALLOWED_HOSTS .
110
+ # If this setting is absent, the default is to use the hostname that was used for the current
111
+ # request.
112
+ saml_allowed_hosts = set (getattr (settings , 'SAML_ALLOWED_HOSTS' , [request .get_host ()]))
113
+
114
+ if not is_safe_url (url = came_from , allowed_hosts = saml_allowed_hosts ):
109
115
came_from = settings .LOGIN_REDIRECT_URL
110
116
117
+
111
118
# if the user is already authenticated that maybe because of two reasons:
112
119
# A) He has this URL in two browser windows and in the other one he
113
120
# has already initiated the authenticated session.
@@ -348,7 +355,15 @@ def assertion_consumer_service(request,
348
355
if not relay_state :
349
356
logger .warning ('The RelayState parameter exists but is empty' )
350
357
relay_state = default_relay_state
351
- if not is_safe_url (url = relay_state , allowed_hosts = {request .get_host ()}):
358
+
359
+ # Ensure the user-originating redirection url is safe.
360
+ # By setting SAML_ALLOWED_HOSTS in settings.py the user may provide a list of "allowed"
361
+ # hostnames for post-login redirects, much like one would specify ALLOWED_HOSTS .
362
+ # If this setting is absent, the default is to use the hostname that was used for the current
363
+ # request.
364
+ saml_allowed_hosts = set (getattr (settings , 'SAML_ALLOWED_HOSTS' , [request .get_host ()]))
365
+
366
+ if not is_safe_url (url = relay_state , allowed_hosts = saml_allowed_hosts ):
352
367
relay_state = settings .LOGIN_REDIRECT_URL
353
368
logger .debug ('Redirecting to the RelayState: %s' , relay_state )
354
369
return HttpResponseRedirect (relay_state )
0 commit comments