Problem/Motivation

Steps to reproduce

1. Upgrade to latest version
2. Log in

Warning: Undefined array key "cookie_samesite" in autologout_user_login() (line 408 of modules/contrib/autologout/autologout.module).

Proposed resolution

TBD

Remaining tasks

fix

Issue fork autologout-3580058

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

dalin created an issue. See original summary.

uberhacker’s picture

StatusFileSize
new545 bytes

See attached patch.

the_g_bomb’s picture

I am not sure this is the correct fix.

There should have been an update hook to make sure the config was added.

See the fix for the other new config variables such as:
https://git.drupalcode.org/project/autologout/-/blob/8.x-1.x/autologout....

the_g_bomb’s picture

As a workaround, this can be fixed by visiting the config page and saving the form.

dalin’s picture

I think this is actually a side effect of a different problem:

Chances are, you aren't needing js_cookie module for anything else. So `composer update drupal/autologout` will remove that module (without a proper uninstall). Because the module is missing, Drupal will refuse to run update hooks.

Do we need to add a note to https://www.drupal.org/project/autologout/releases/2.0.2 to first run `composer require drupal/js_cookie` ?

train’s picture

This issue happens if you don't have this set in docroot/sites/default/services.yml.

parameters:
  session.storage.options:
    # Set the SameSite cookie attribute: 'None', 'Lax', or 'Strict'. If set,
    # this value will override the server value. See
    # https://www.php.net/manual/en/session.security.ini.php for more
    # information.
    # @default no value
    cookie_samesite: Lax
the_g_bomb’s picture

Not sure if the suggestion I made here:
https://git.drupalcode.org/project/autologout/-/merge_requests/83#note_6...
Would fix it. Perhaps I should have been tougher on getting that added.

uberhacker’s picture

These kinds of warnings happen way too often and it's usually because there is not enough effort put into making sure the data (or lack of) is handled correctly in code.

the_g_bomb’s picture

Thanks for the reports and investigation, everyone. I've done some digging and can clarify what's happening here.

This is not related to js_cookie or requiring update hooks. The cookie_samesite key does indeed come from Drupal core's session.storage.options container parameter, not from module configuration.

cookie_samesite was added to core/core.services.yml in Drupal 10.1 (https://www.drupal.org/project/drupal/issues/3150614).

Sites set up before 10.1 may have a sites/default/services.yml file copied from default.services.yml, when cookie_samesite wasn't included.

Sites with no services.yml, or set up after 10.1, should not be affected as core's defaults apply correctly.

This confirms @train's finding, adding cookie_samesite: Lax to your services.yml under session.storage.options is the correct site-level fix.

A module fix (!empty() instead of ?:) as per the patch supplied by @uberhacker, can also be applied to two occurrences in autologout.module (in autologout_user_login() and autologout_page_attachments_alter()), so the warning will no longer occur regardless of Drupal version or services.yml state.

I'll get an MR prepared asap

jannakha’s picture

+1 for #6 solution
my services.local.yml didn't have cookie_samesite: Lax

thanks for investigating the issue!

joseph.olstad’s picture

seeing this also

dalin’s picture

@uberhacker
Your comments are not helpful and more likely to cause the opposite of what you're hoping for.

Thanks to all who have contributed to this release. I'm sure that much (?all) of your time was volunteered.

joseph.olstad’s picture

MR 93 completely resolves the issue, recommend merging this fix. Our build started on Drupal 8.9, we're now on Drupal 11.3.5. Should work with and without cookie_samesite

uberhacker’s picture

@dalin: I fixed the issue which is a bug. You're welcome.

the_g_bomb’s picture

This isn't a bug; not keeping the services.yml file up to date is not the issue with this module.
Adding an if empty is a defensive programming practice that guards against problems elsewhere.

I am also going to add something to the README to make sure users are aware that session.storage.options: needs to be kept up to date in the services.yml file

the_g_bomb’s picture

I have to admit, I was a bit insulted that you think this was due to a lack of effort.
I have been working on dozens of tickets over the last few months to get this module up to a better standard. This ticket #3308456: Autologout cookie is not secure has been open since 7 Sep 2022, and I don't see your code review suggesting that things should be done differently @uberhacker. So perhaps if you wish to comment about a lack of effort, it shouldn't have been framed as a criticism but rather as an apology.

the_g_bomb’s picture

That being said, I will put my hands up and admit it was an oversight on my part to assume cookie_samesite: Lax would be set correctly in the session.storage.options; this module supports ^9.2 || ^10 || ^11, so I should have accounted for it not being set. Sorry.

the_g_bomb’s picture

Status: Active » Needs review
deaom’s picture

Status: Needs review » Reviewed & tested by the community

Removed the cookie_samesite from core.services.yml cleared cache and then logged in. There is no error present and the cookie is set as Lax, so marking this as RTBC.

joseph.olstad’s picture

We're using hundreds of modules and no others threw an undefined array key error on every single authenticated page load of the website. I recommend merging.

natnatalia changed the visibility of the branch 3580058-php-warning-after to hidden.

natnatalia changed the visibility of the branch 3580058-php-warning-after to active.

natnatalia’s picture

StatusFileSize
new1.13 KB

Hi everyone,
I just wanted to share another possible approach for this solution that I developed before coming across this Drupal issue.

joseph.olstad’s picture

Hi @natnatalia , yes can please you roll in your changes into the MR 93 please? It is an improvement IMHO. Press the big get access button up top and follow the instructions at "Show commands"

the_g_bomb’s picture

Updated

uberhacker’s picture

Thank you @natnatalia! Yes, your patch is more elegant. However, I wasn't able to apply it. Attached is an updated patch that should work for both 2.0.2 and 2.x-dev presently.

niral098’s picture

#27 patch works with 2.0.2 version. Thank you!

the_g_bomb’s picture

the_g_bomb’s picture

Patch files are no longer recommended, use merge requests instead.

gold’s picture

Title: PHP warning after upgrade to 2.02 » Undefined array key "cookie_samesite" warning after upgrade to 2.02

The MR!93 at #26 applies and is working for me.

I'd give a +1 for RTBC.

Updating the title too. There's 2 other issues that were closed as duplicates of this one. This should make it easier to find.

the_g_bomb’s picture

Status: Reviewed & tested by the community » Fixed

Merged

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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

juburin’s picture

I saw, that there are some fixes after the latest update (2.0.2). Is there a release planed?

the_g_bomb’s picture

Yes, getting the ducks in a row.

I want to create one last 2.x and 8.x-1.x release and also a new 3.x release that can remove the D9 and >10.2 support.

I am needing to get gitlab permissions increased before then, though.

ressa’s picture

@juburin: I suggested granting @the_g_bomb the Maintainer role in #3497097: Offering to co-maintain Automated Logout, without luck ... maybe because the issue is closed, the Maintainers don't follow it?

@the_g_bomb: Maybe you need to create a formal application issue? If useful as inspiration, here's a "request Maintainer role" issue from another project: #3556750: Applying for 'Maintainer' role for the project Block Class on Gitlab.

kwfinken’s picture

Any new status on a release?

v.dovhaliuk’s picture

Since using MR as patches is a security issue, the patch file was provided. (Waiting for the new release)