Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle "next" query string param in CustomLogoutView #2064

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@
user, provider=OlOpenIdConnectAuth.name
).first()
id_token = user_social_auth_record.extra_data.get("id_token")
qs_next = self.request.GET.get("next")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use social auth's redirect sanitization for this: https://github.com/python-social-auth/social-core/blob/master/social_core/actions.py#L27-L31. You'll need to pull the value of allowed redirects more directly from the settings though.

qs = urlencode(
{
"id_token_hint": id_token,
"post_logout_redirect_uri": self.request.build_absolute_uri(
settings.LOGOUT_REDIRECT_URL
),
"post_logout_redirect_uri": qs_next
if qs_next
else self.request.build_absolute_uri(settings.LOGOUT_REDIRECT_URL),
}
)

Expand All @@ -55,7 +56,7 @@
**kwargs, # noqa: ARG002
):
"""
GET endpoint for loggin a user out.
GET endpoint for logging a user out.

The logout redirect path the user follows is:

Expand All @@ -68,6 +69,6 @@
user = getattr(request, "user", None)
if user and user.is_authenticated:
super().get(request)
return redirect(self._keycloak_logout_url(user))

Check warning

Code scanning / CodeQL

URL redirection from remote source Medium

Untrusted URL redirection depends on a
user-provided value
.
else:
return redirect("/app")
Loading