question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Post-logout redirect never fires

See original GitHub issue

I was planning to submit a PR here today, but I’ve hit a roadblock. Setup:

We use django_cas_ng and our users auth against a CAS SSO system. When they click the Logout link on our site, they are logged out of the site AND redirected to our campus SSO system’s logout page, which kills their ticket. This is important, especially for multi-user lab computers.

After installing django-session-security, clicking the Logout link manually still works normally. But if I let a user time out with DSS, they are logged out but they are NOT redirected to the SSO logout view. They stay on the site. In this state, the user can click the Login link again and be logged in automatically again without having to authenticate (because the CAS session ticket is still alive). That’s bad.

So I started a PR that lets the dev set a custom logout URL. If present, the middleware.py adds a simple redirect after logout():

        if delta >= timedelta(seconds=expire_seconds):
            logout(request)
            return HttpResponseRedirect(settings.LOGOUT_REDIRECT_URL)

(this is in process_request()). The problem is that the redirect never happens after timeout - the user is logged out but the page is not redirected to settings.LOGOUT_REDIRECT_URL. I don’t understand why.

If I modify it to go to the CAS logout page without performing an internal logout first:

        if delta >= timedelta(seconds=expire_seconds):
            return HttpResponseRedirect(settings.LOGOUT_REDIRECT_URL)

Then a timeout logout does redirect, but if the user then tries to go back to the site (e.g. to log in as someone else), they’re stuck in a loop eternally handing off to settings.LOGOUT_REDIRECT_URL, so they can’t access the site at all.

I can’t seem to make this work either way. Any idea what I’m missing here? It seems clear that No. 1 is what I want, but I can’t figure out why the redirect never fires.

n.b. I also have code to call django_cas_ng’s logout() function rather than Django’s, but that doesn’t affect the problem - it’s the same either way.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:62 (36 by maintainers)

github_iconTop GitHub Comments

2reactions
claytondaleycommented, Nov 16, 2017

If you call logout from a view, you would normally return the response. As you can see here (links to an older version of Django because the interface recently changed), one of the possible responses conveys redirect information. As you saw, the middleware does not return the response. All it does is trigger the database-side processing for the logout.

But the “answer” isn’t to change session security because the application cannot be responsible for timing out the SSO credential… the SSO server needs to do that. Consider the simplest case:

  • User A logs into the application
  • User A closes the browser window holding the application (there’s no opportunity to redirect, even if supported)
  • User B opens a new window and goes to email

Because User A’s SSO session is still alive, User B is routed to the User A’s email. There’s nothing that session security can do to take care of this. The SSO server needs to timeout the SSO session.

The application also needs a timeout so application sessions don’t outlast the SSO sessions (by more than the timeout), but session security already handles this.

1reaction
santosh9991commented, Apr 11, 2018

@claytondaley : It worked in the production. Thank you for the help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to configure where to redirect after a log out in Django?
Just wondering where I can set the url to redirect to after logout. I know you can set the login url. I want...
Read more >
Redirect Users After Logout
You can redirect users to a specific URL after they logout. You will need to register the redirect URL in your tenant or...
Read more >
Modify Session Security Settings
Configure Logout Page Settings · From Setup, in the Quick Find box, enter Session Settings , then select Session Settings. · Select Store...
Read more >
Handling Logouts :: Spring Security
The LogoutSuccessHandler is called after a successful logout by the LogoutFilter , to handle (for example) redirection or forwarding to the appropriate ...
Read more >
Using the Django authentication system
If called via POST with user submitted credentials, it tries to log the user in. If login is successful, the view redirects to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found