Closed (fixed)
Project:
Automated Logout
Version:
2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
7 Sep 2022 at 19:56 UTC
Updated:
3 Apr 2026 at 13:30 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
dylan donkersgoed commentedI'm out of time for today but plan to attach a patch tomorrow.
Comment #4
john.oltman commentedUploading a patch for use until this is merged and released
Comment #5
dylan donkersgoed commentedI added the ability to set cookie lifetime to the patch as well since the scan was flagging that with a similar error (wanted the cookie to be temporary). Also, I forgot to mention in the initial commit but this allows settings the samesite attribute (also flagged by the scan) in addition to the secure attribute.
Comment #6
ramonvasconcelos commentedI'll review it.
Comment #7
ramonvasconcelos commentedThe changes are working as intended but it also broke a lot of tests. Mostly related to the missing schema for
cookie_lifetime. I'll see if i can fix them.Comment #8
ramonvasconcelos commentedDone.
Comment #9
alexanderj commentedi will review it.
Comment #10
alexanderj commentedThe changes are working great, I tested it in my local environment following the step by step and everything went as expected, so I'm moving to RTBC.
Comment #11
jiisuominen commentedI think this patch needed httpOnly parameter as well.
So I updated patch at #4, to include httpOnly option.
Comment #12
johan_vm commentedPatch #11 works fine, but REQUEST_TIME is deprecated, so I added a small fix for that.
Comment #15
deaom commentedI added the post update hook for the new settings, so existing users have values set and they only need to export the configuration (to have it set "default"). And also applied the changes from patch in comment #12
The testing is now done via GitLab CI and test are passing, so setting the status to needs review and "hidding" the patch files, as the issue fork exists and all changes should be done there.
Comment #16
admirlju commentedWhen the user logs in the cookie correctly sets values of the cookie. The problem comes when JS sets a new cookie
cookies.set("Drupal.visitor.autologout_login", Math.round((new Date()).getTime() / 1000));this resets all values toNone.Looking into fixing it.
Comment #17
admirlju commentedNow the cookie setting in JS also adds the configurations.
Comment #18
deaom commentedGood catch for the JS configuration. Just removed the casting from int as it's not necessary and updated post update hook to use correct variable for lifetime. The code works, it sets the cookie base on the settings defined in the configuration, so marking this as RTBC.
Comment #19
jonraedeke commentedThis is working really, except that the settings form always reverts back to the default value for cookie lifetime. To replicate, change the value to `0` and save. The form will show `31536000`.
Comment #20
jonraedeke commentedThere appears to be something wrong with the logic. After the initial timeout, the user is presented with a dialog on every page request. I have it set to "Logout user regardless of activity".
Comment #21
rishabjasrotia commentedComment #22
rishabjasrotia commentedComment #23
rishabjasrotia commentedComment #24
rishabjasrotia commentedUpdated code for issue to set cookie lifetime to 0
Comment #25
rishabjasrotia commentedComment #26
jonraedeke commentedI figured out why the timer never gets reset after the initial one times out when the module is configured to "Logout user regardless of activity". The cookie with HttpOnly configured to true cannot be accessed by js, so
var login_time = cookies.get("Drupal.visitor.autologout_login");is undefined.So the HttpOnly setting is currently incompatible with the "Logout user regardless of activity" setting.
Comment #27
rishabjasrotia commentedHello @jonraedeke,
I can have a look into js undefined error.
Comment #28
rishabjasrotia commentedI think we can remove the HttpOnly from this patch and keep the rest.
Do let us know your opinion @jonraedeke
Comment #29
happy047 commentedRecently, I have updated to the latest [1.5] release of this module and I have also faced the same issue of cookies being undefined error.
However, if you go to the autologout.libraries.yml file, you can see it is dependent on the libraries of [https://www.drupal.org/project/js_cookie] module.
You can install and enable the module and the cookie_undefined error will be resolved.
Comment #30
fernandaporto commentedHello, I've re-rolled the patch based on the latest merge request #23
It was falling due to this line on the autologout.settings.yml file
Comment #31
japerryComment #32
o'briatSo, what's left :
Comment #33
o'briatComment #36
the_g_bomb commentedI have:
So, what's left :
Force HttpOnly to false and remove it from the admin formUpdate the MR with the minor fixes from 3308456-30.patch #30Change the MR target branch to 2.x (or create a new one if this fix should still apply to 1.x)Comment #37
the_g_bomb commentedComment #38
mglamanDrupal Core added the
cookie_samesitetosession.storage.optionsservice parameter. This should be used over an override by autologout. Same with thecookie_lifetimevalue.Comment #39
japerryMarking NW per comment #38. Because of the new service parameter, this module should just those values. Note, that option was added in Drupal 10.1.
It'd be preferable to not have additional config. To that end, samesite and lifetime settings do not need to be set. For Drupal 10+, use core's settings. For Drupal 10.0 and lower, just set a default 'Lax' and cookie lifetime to 1 month? 1 year seems long. This maintains compatibility with older versions of Drupal that likely wouldn't need anything but the defaults anyway.
Also, shouldn't the cookie secure setting default to TRUE? Sites should be on https and only need this override in cases like https->http load balancer setups. If you're running on http and forget to set it to FALSE, not quite sure what will happen there, but not sure we should care...
Comment #40
the_g_bomb commentedUsing the new service parameter also change the patch to make the module only available to Drupal 10.1 and above.
We can backport a different solution for earlier versions if required.
For the backport I would think we should copy the current core setting which is 200000 and set 'Lax' by default.
I have removed the additional config for samesite and lifetime settings, but grabbed those values from core and added them to the JS settings.
I left the cookie secure setting default to FALSE just in case sites don't have an SSL cert. I am also not sure what will happen if that is on without one, so thought it best to leave it as False as turning it on is easier than potentially debugging an error if it is on and causes problems.
Comment #41
the_g_bomb commentedIf anyone needs a patch this can be used: https://git.drupalcode.org/project/autologout/-/merge_requests/71.diff
Comment #42
renatog commentedAware about patch link on #41 however if MR is updated the patch is updates as well
So uploading the same patch in a file to avoid being updated. So it can be used on composer if needed
Comment #43
deaom commentedMarking this as RTBC as the checkbox is there and the settings are getting set. One small observation, if user is already logged in when the change in settings happens, the users needs to log out and log in again for changes to take.
Comment #45
inregards2plutoI tried to rebase this one using the latest 2.x from the upstream repository, but I think a wire is getting crossed somewhere :/ I can't rebase the branch from GitLab UI since the merge conflict in `autologout.js` needs to be resolved manually.
I think this particular forked repos `2.x` branch isn't hooked up to the 2.x from the main autologout repo?
Would a maintainer mind merging in the updated project:2.x into the 2.x for this repo? Happy to resolve the merge conflict after.
Comment #46
the_g_bomb commentedThe removal of jscookie was needed to allow the composer test to pass, which was blocking the merge of the #3339695: Use Drupal.dialog call instead of jQuery dialog.
As both the js cookie and this are both dealing with the setting of cookies, there are merge conflicts that will need to be addressed.
I'll bring the 2.x branch in asap to keep momentum at least.
Comment #47
the_g_bomb commentedThere are probably enough changes to warrant another review.
Comment #48
inregards2plutoTested on my local with a Drupal 11.2.8 site and I'm experiencing a couple of issues:
1) I get an error on the site that says "Undefined array key "cookie_samesite" in /var/www/html/web/modules/custom/autologout-3308456/autologout.module". I was able to fix this by updating the operator from "?:" to "??" so that it didn't try to access the undefined array key and would fall back on "Lax" in those cases.
2) It seems like the toggle isn't working? The cookie is spawning regardless of whether I have the option in the config form toggled or not, even when the cookie shows as not being secure and the samesite value is "Lax". I tried logging out and logging back in per Comment #43, but am still seeing the cookie spawning.
I'm stepping away for the moment, but will keep troubleshooting this tonight.
I'll admit that working with cookies is newer territory for me, so if someone more experienced wants to verify this behavior to make sure this isn't a PEBCAK issue on my part, that'd be great. Otherwise, I'll keep working at it.
Comment #49
deaom commented1) is getting the options from the core setup:
so the array key needs to exists. I'm testing with D 11.3.1 and do not have that issue.
2) Why would the cookie not get generated or spawned? It still does, just has the Secure option set to false instead of true, and vice versa when checkbox is checked.
I would say this is still working as it was before, so it can be RTBC, but leaving status as is, if somebody else also wants to have a go at testing.
Comment #50
inregards2plutoGotcha. I may have been misinterpreting the intended behavior in that case.
When I read the help text for the configuration option ("Specifies whether or not the cookie should only be transmitted over a secure HTTPS connection. The cookie will only be set if a secure connection exists."), I was interpreting that as "'Set' = 'Generated'. Therefore, if this is on and the connection is not secure, there should be no cookie."
I definitely yield to more knowledgeable folks in this case for the rubber stamp of approval.
Comment #51
the_g_bomb commentedJust to be clear I re-ran my own tests:
I saw this in the console

Comment #52
the_g_bomb commentedTrying to think of a scenario where we may get:
"Undefined array key "cookie_samesite"
Do you think you need to run the update hook to ensure the settings include the new configuration?
Comment #53
inregards2plutoI think I found my problem with the "Undefined array key "cookie_samesite".
When I got that error, the way that I was testing the issue was by creating patches from the forked issue and applying them to the stable version of the module on the existing site I'm working on. I'd noticed that some of the commit patches weren't applying, but tried trucking on, but was getting the errors I mentioned.
Given the weirdness and that fact others were getting different results, I tried making a fresh sandbox site this AM and cloning the forked repo into my "modules/custom" directory.
I ran "drush en -y autologout" and got an error that I was missing the "js_cookie" module dependency. I added that and the module enabled fine and, with no additional code changes, I'm no longer getting the "Undefined array key "cookie_samesite".
So I think the weirdness I was getting was the fact I didn't have the js_cookie module dependency. Because my first method of patching was for an already installed and enabled version of autologout, I didn't see the missing dependency issue, just the downstream error message that was ultimately due to the missing dependency.
I looked back through this issue and saw Comment #29 actually had a similar issue. I wonder if we should update the composer.json for this module so that it automatically pulls in the js_cookie module on install?
Comment #54
deaom commentedjs_cookie dependency was removed in #3557620: Remove JS Cookie dependency. Did not follow why, just that it was. If the module is cloned with it 2.x branch and then switched to the MR, there should be no issues with the js_cookie dependency. So I'm thinking this is just a user error maybe, probably?
Comment #55
inregards2plutoI am 100% willing to chalk it up to user error. I know this is the last big issue on the new release roadmap, so I'm personally comfortable calling it a PEBCAK issue on my part so that we can get it merged in and cut the new release.
If the issue persists after updating the new release, I can circle back up with a separate issue ticket.
Comment #56
deaom commentedWe can then set it to RTBC as @the_g_bomb also confirmed it working for him.
Comment #58
the_g_bomb commentedMerged, thanks all
Comment #62
ericgsmith commentedHi team,
Please don't use "Implements hook_post_update_NAME()." as a doc block for an update hook - it really needs to be a description to the user about what the update hook is doing.
Currently it displays like this when running updates:
Comment #63
renatog commented#62 makes sense
This description is useful for people when reviewing the database updates
Comment #65
deaom commentedThe original issues is already fixed, but to not create more issues, created a new branch, where the only change is the comment mentioned in #62.
Comment #66
the_g_bomb commentedReviewed and tested
Comment #67
renatog commented+1 approval on MR 96