Problem/Motivation

We ran into a bug where users are redirected to the homepage if their SAML session has expired in SimpleSAMLphp while their Drupal session has not.

This is especially problematic in a path-based multisite environment since the user gets redirected to the domain homepage and as a result ends up on a different website (e.g. if they try to access https://example.com/mysite/mypage then they are redirected to https://example.com).

Steps to reproduce

Manually expiring a SAML session is tricky so let's use a local Drupal account (user 1) to simulate the case where as SAML session has expired whereas a Drupal session has not.

  1. Enable and configure simplesamlphp_auth
  2. Go to /admin/config/people/simplesamlphp_auth/local
    1. Check box Allow authentication with local Drupal accounts
    2. Set field Which users should be allowed to login with local accounts? to 1
  3. Authenticate locally as user 1 (e.g. execute drush user:login) ; this creates a session in Drupal which has no corresponding SAML session
  4. Disallow local authentication: drush -y config:set simplesamlphp_auth.settings allow.default_login false --input-format=yaml
  5. Load any page of your website - say, https://example.com/mysite/mypage
  6. Expected result: You get logged out however the page you requested (https://example.com/mysite/mypage) still loads and renders as an anonymous user
  7. Actual result: Your get logged out and are redirected to the domain homepage i.e. https://example.com

Proposed resolution

The module includes an event subscriber SimplesamlSubscriber.php that fires on all requests and checks the authentication status of the user. This includes some logic that redirects to / when the user:

  1. Has a valid Drupal session (is not anonymous)
  2. Has no SAML session
  3. Is not allowed to sign in locally

Instead of redirecting the user to / I think it would be best to redirect to the current page, as was the case in Drupal 7. Indeed in Drupal 7, when the conditions above are met, the module logs out the user by calling user_logout() which itself calls drupal_goto() which redirects to the current path.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

fengtan created an issue. See original summary.

fengtan’s picture

Status: Active » Needs review
StatusFileSize
new680 bytes

Opened Merge Request !48 and attached a corresponding patch file for easy installation with Composer.

jogordon’s picture

Thanks @fengtan! This patch resolves an issue with our SSO that has been reported from many of our users.

Our issue:

  • Users were clicking on a link to our site and being redirected to the homepage.

Conditions to replicate:

  • A site editor logs into one of our sites via SSO to create or edit some content
  • The user does not log out but tabs/browser may be closed
  • Our simplesamlphp config specifies a session duration of 8 hours
  • After 8 hours, the same user clicks on a link to a page and they are redirected to the homepage
  • The logs show a ‘Session closed’ message for that user

Steps to replicate

Session duration amended to 5 minutes for testing purposes

Steps before patch added:

  • User logged into the site via SSO
  • Close all tabs and browser
  • Wait 5 minutes (session duration)
  • Click on link from external source
  • User is redirected to the homepage

Steps after patch added:

  • User logged into the site via SSO
  • Close all tabs and browser
  • Wait 5 minutes (session duration)
  • Click on link from external source
  • User is directed to the correct/desired path and not the homepage

Happy that this patch solves our issue.

nmangold’s picture

Status: Needs review » Reviewed & tested by the community

I was able to replicate the issue as described, and confirmed the patch fixes the issue with no noticeable regressions.

Marking RTBC.