Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

insight's avatar

How to change the 'laravel_session' and 'XSRF-TOKEN' Expires/Max-age value to 'Session' instead of a timespan ?

Dear Friends, I am using Laravel 10.10 . As part of my application security audit the team compel to change the value of Expires/Max-age value of 'laravel_session' & 'XSRF-TOKEN' to "Session". Please see the screenshot Screenshot

My required model is

Screenshot

Waiting your reply

Thanks

Anes P A

0 likes
13 replies
insight's avatar

@s4muel As per expert opinion "'expire_on_close' => true: When you set this option to true, the session cookie will have no specific expiration time set, and it will be deleted when the user closes their browser (i.e., when the browser session ends). The Expires and Max-Age attributes of the cookie will not be set, effectively making it a session cookie." In my case too it's not working , I already set it..

Thanks

Anes P A

s4muel's avatar

@insight exactly as you say "...effectively making it a session cookie", that is what it is, the value "Session" you see is just fictional, not a real value, to indicate it it a session cookie

s4muel's avatar

@insight do i see correctly, that you set 'expire_on_close' => true in config/session.php as your solution (as in the url you posted) or am i missing something?

s4muel's avatar

@insight and what was the main problem then?

did you try setting it (just the expire_on_close) on fresh laravel project? try it and see for yourself that it just works as you want. and find out why it doesnt work on your current project. instead of messing up with custom session and csrf middlewares that can bite you in the future.

and what is the purpose of this? 'lifetime' => env('SESSION_LIFETIME', 'Session') do you even use it anywhere? 🤯

insight's avatar

@s4muel That line has not any special significance. I already set

SESSION_LIFETIME=120

in .env file . So 2 hours (120 mins) will take in effect on that line.

Snapey's avatar

@insight expect your security people to complain that cookies are not https only

you should also remove 'Session' from this line

'lifetime' => env('SESSION_LIFETIME', 'Session'),

as it is misleading and nothing to do with the solution

insight's avatar

So remove 'Session' and put that line like

'lifetime' => env('SESSION_LIFETIME',  120),

If I like to give session time out as 2 hours . Am I right @Snapey ?

Snapey's avatar

@insight

You still don't understand env() function?

parameter 1 is the environment variable to use

parameter 2 is the FALLBACK default value if the environment key is not found

So in your example, the session lifetime will be set to 120 ONLY IF the .env has no SESSION_LIFETIME

Please or to participate in this conversation.