Skip to content

Commit 9853690

Browse files
author
Chander Ganesan
committed
Update to also address the other case where we check for safe redirect URLS
1 parent 046ebf4 commit 9853690

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

djangosaml2/views.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,14 @@ def assertion_consumer_service(request,
338338
if not relay_state:
339339
logger.warning('The RelayState parameter exists but is empty')
340340
relay_state = default_relay_state
341-
if not is_safe_url_compat(url=relay_state, allowed_hosts={request.get_host()}):
341+
342+
# Ensure the user-originating redirection url is safe.
343+
# By setting SAML_ALLOWED_HOSTS in settings.py the user may provide a list of "allowed"
344+
# hostnames for post-login redirects, much like one would specify ALLOWED_HOSTS .
345+
# If this setting is absent, the default is to use the hostname that was used for the current
346+
# request.
347+
saml_allowed_hosts = set(getattr(settings, 'SAML_ALLOWED_HOSTS', [request.get_host()]))
348+
if not is_safe_url_compat(url=relay_state, allowed_hosts=saml_allowed_hosts):
342349
relay_state = settings.LOGIN_REDIRECT_URL
343350
logger.debug('Redirecting to the RelayState: %s', relay_state)
344351
return HttpResponseRedirect(relay_state)

0 commit comments

Comments
 (0)