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.
- Enable and configure
simplesamlphp_auth - Go to
/admin/config/people/simplesamlphp_auth/local - Check box
Allow authentication with local Drupal accounts - Set field
Which users should be allowed to login with local accounts?to1 - Authenticate locally as user 1 (e.g. execute
drush user:login) ; this creates a session in Drupal which has no corresponding SAML session - Disallow local authentication:
drush -y config:set simplesamlphp_auth.settings allow.default_login false --input-format=yaml - Load any page of your website - say, https://example.com/mysite/mypage
- Expected result: You get logged out however the page you requested (https://example.com/mysite/mypage) still loads and renders as an anonymous user
- 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:
- Has a valid Drupal session (is not anonymous)
- Has no SAML session
- 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | simplesamlphp_auth-3568305-1-user_redirected_saml_auth_drupal_auth.patch | 680 bytes | fengtan |
Issue fork simplesamlphp_auth-3568305
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
Comment #3
fengtanOpened Merge Request !48 and attached a corresponding patch file for easy installation with Composer.
Comment #4
jogordon commentedThanks @fengtan! This patch resolves an issue with our SSO that has been reported from many of our users.
Our issue:
Conditions to replicate:
Steps to replicate
Session duration amended to 5 minutes for testing purposes
Steps before patch added:
Steps after patch added:
Happy that this patch solves our issue.
Comment #5
nmangold commentedI was able to replicate the issue as described, and confirmed the patch fixes the issue with no noticeable regressions.
Marking RTBC.