Login form always show "Login ticket invalid. Please try again" after submission in 10.3

Created on 29 July 2024, 2 months ago
Updated 29 August 2024, about 1 month ago

Problem/Motivation

Hi!

using the latest version of cas_server (2.0) on a drupal 10.3.1 and PHP8.3, we are encountering the following issue when trying to do login via CAS.
The steps to reproduce this are:
1. Open a private session on the browser, so no cookies are on both sites (server and client)
2. Open the client page and use the 'login with CAS' to be redirected to the server
3. On the server site, fill username and password and login. The message "Login ticket invalid. Please try again" is presented

However, if you before step 3, you have visited the server site before or you are already logged in, then 3 does not fail.

In a more detailed explanation, it seems:
The form is rendered via a 'GET' request.
Then, the moment the 'submit' button of the CAS server login form is clicked, it seems it triggers a call to buildForm first via a 'POST' request (and making $_SESSION to be empty) and submitForm() right after executed, with empty values of $_SESSION again, making hte form to fail

WE are not sure what is triggering this issue (php8.3 or 10.3.1), as we did update our platforms to both latests versions simultaneously

Steps to reproduce

See above

Proposed resolution

Will open a MR soon agains 2.1.x although the fail is in 2.0 (but can be backported and cherrypicked to that branch)

Remaining tasks

  • ✅ File an issue
  • ✅ Addition/Change/Update/Fix
  • ✅ Testing to ensure no regression
  • ❌ Automated unit testing coverage
  • ✅ Automated functional testing coverage
  • ✅ Security
  • ✅ Code review by maintainers
  • ✅ Credit contributors
  • ✅ Release notes snippet
  • ❌ Release

User interface changes

  • N/A

API changes

  • N/A

Data model changes

  • N/A

Release notes snippet

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇧🇪Belgium gorkagr

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @gorkagr
  • Merge request !20Draft: Resolve #3464380 "Login form always" → (Closed) created by gorkagr
  • Status changed to Needs review 2 months ago
  • 🇧🇪Belgium gorkagr

    MR added with a proposed solution that does work in our websites, making the error and the wrongfully redirection to disappear.

  • Pipeline finished with Success
    2 months ago
    Total: 216s
    #237010
  • Status changed to Needs work 2 months ago
  • 🇦🇺Australia elc

    This MR isn't going to be merged into the branch. The session handling is something I have been looking into especially with the recent changes to sessions introduced back in Drupal 9.2. Session lazy start, and the session id no longer being reliable readble.

    Drupal auto-creates the session so manually starting it like this would be problematic in module code. If it's working for you now that's great, but long term the session handling needs to change for this module.

    I do have some proposed code to work on this but it's all in a new branch which is pretty much a re-write but have so far been unable to start committing it due to a bit of hang up on one of the first issues I worked on. I will need to post this soon. My thought was the push session related variables into the private store which would automatically trigger the full session. I think the true Drupal way would be to lazy load the LT into the form and not store it in the session at all as that's not part of the spec anyway.

    I'm also running a number of sites on D10.3 + CAS Server which aren't having the same issues as you. It might be that I use the gateway feature on a number of key pages on the site which send the user to the CAS Server prior to their attempted login which may initiate the session then.

    Setting back to NW since this does need work but this MR won't be merge in.

  • Status changed to Needs review about 2 months ago
  • 🇦🇺Australia elc

    Can you see if this solves your issue? It's removing the LT from the $_SESSION completely, and using the LT for the purpose it was meant to be used which is to prevent replays of submissions due to bugs or attacks.

    Tests need to be updated as the LT has tests.

    Moved back to 2.0.x branch as the 2.1.x branch is D10.2||D11 at present and not presently a supported release. It would be ported to 2.1.x later in the branch.

    This will not be ported to to 8.x-1.x branch.

  • 🇦🇺Australia elc

    While trying to fix these tests, it has become apparent that session handling inside the module is now borked for all tested Drupal 10 core versions; The D9 still works.

    This was supposed to be broken a while ago but it was still working 4 days ago. Something has changed and now the session id returned is wrong.

    I'll leave this as needs review, but the tests will not pass as they stand here. New issue needed for fixing all of the session handling which will need to move to something stored in the session instead of the session id itself.

    It would be appreciated if you could test the LT changes in MR!21 and confirm if that is working for you, although the problems will session ids might be causing deeper problems.

  • 🇧🇪Belgium gorkagr

    Hi!

    Thnks for the quick reaction to the issue.
    I cannot test it before the 12th, but i will do it first thing on that day :)

    Best

  • 🇦🇺Australia elc

    You'll need to patch off the current 2.0.x HEAD as there have been a few additions to fix the session handling which is probably related.

    (It should be possible to patch this issue into 2.0.0 without HEAD/two above with a little wiggling)

    I have so far been unable to replicate the problem with your steps, even with an exact match of setup and a few variants. I do however feel that this is probably a good change to merge in. I'm just more curious to see if this fixes the issue for you now.

  • 🇦🇺Australia elc

    ELC changed the visibility of the branch 3464380-login-form-always to hidden.

    • ELC committed 0a6d2709 on 2.1.x
      [#3464380] Use #lazy_builder to add LT to login form
      
  • 🇦🇺Australia elc

    @gorkagr Did you have a chance to test out if it fixed the problem for your situation? If that's working, it'll be ready for the 2.0.1 release.

  • 🇧🇪Belgium gorkagr

    Hi!
    Tomorrow I will do the testing, i did not have time these last days due to last-minute urgent fixes on one project.
    but those are done already, so tomorrow I will be able to jump on this

    Sorry for the delay

  • Status changed to RTBC about 2 months ago
  • 🇧🇪Belgium gorkagr

    In localhost,

    first replaced the 2.0.0 version with the last in dev (dev-2.0.x 25cbfc8)
    then applied MR 21 (as is 2.0.x) code as a patch via composer
    a little bit of drush cr...

    and then all good, if i repeat the steps from the original IS

    1. Open a private session on the browser, so no cookies are on both sites (server and client)
    2. Open the client page and use the 'login with CAS' to be redirected to the server
    3. On the server site, fill username and password and login. Good!!

    step 3 is executed good and redirects to the client site succesfully :)

    Many thnks for the patch!!

    • ELC committed b6652343 on 2.0.x
      [#3464380] Use #lazy_builder to add LT to login form
      
  • Status changed to Fixed about 2 months ago
  • 🇦🇺Australia elc

    Thank you @gorkagr!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024