Skip to content

ACS_DEFAULT_REDIRECT_URL has no effect #278

Closed
@pandafy

Description

@pandafy

It seems like LOGIN_REDIRECT_URL overrides ACS_DEFAULT_REDIRECT_URL setting.

On accessing saml2/login/ endpoint with no next parameter, the next_path defaults to LOGIN_REDIRECT_URL

def get(self, request, *args, **kwargs):
logger.debug('Login process started')
next_path = self.get_next_path(request)

def get_next_path(self, request: HttpRequest) -> str:
''' Returns the path to put in the RelayState to redirect the user to after having logged in.
If the user is already logged in (and if allowed), he will redirect to there immediately.
'''
next_path = settings.LOGIN_REDIRECT_URL
if 'next' in request.GET:
next_path = request.GET['next']
elif 'RelayState' in request.GET:
next_path = request.GET['RelayState']
next_path = validate_referral_url(request, next_path)
return next_path

This next_path is used to set value of relay_state here:

if not http_response:
# use the html provided by pysaml2 if no template was specified or it doesn't exist
try:
session_id, result = client.prepare_for_authenticate(
entityid=selected_idp, relay_state=next_path,
binding=binding, **sso_kwargs)
except TypeError as e:
_msg = f"Can't prepare the authentication for {selected_idp}"
logger.error(f'{_msg}: {e}')
return HttpResponse(_msg)
else:
http_response = HttpResponse(result['data'])
else:
raise UnsupportedBinding(f'Unsupported binding: {binding}')

Now in post method of AssertionConsumerServiceView, value of ACS_DEFAULT_REDIRECT_URL is retrieved, but that's get overridden by the RelayState parameter of POST request, which was set in saml2/login if I am not wrong.

def build_relay_state(self) -> str:
""" The relay state is a URL used to redirect the user to the view where they came from.
"""
login_redirect_url = get_custom_setting('LOGIN_REDIRECT_URL', '/')
default_relay_state = get_custom_setting(
'ACS_DEFAULT_REDIRECT_URL', login_redirect_url)
relay_state = self.request.POST.get('RelayState', default_relay_state)
relay_state = self.customize_relay_state(relay_state)
if not relay_state:
logger.warning('The RelayState parameter exists but is empty')
relay_state = default_relay_state
return relay_state

Hence ACS_DEFAULT_REDIRECT_URL has no result in this scenario.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions