Skip to content

Improve session config and cookie store (part of #7685)#7689

Open
Zoey2936 wants to merge 2 commits intomainfrom
improve-session-config-cookies
Open

Improve session config and cookie store (part of #7685)#7689
Zoey2936 wants to merge 2 commits intomainfrom
improve-session-config-cookies

Conversation

@Zoey2936
Copy link
Collaborator

@Zoey2936 Zoey2936 commented Mar 4, 2026

No description provided.

Signed-off-by: Zoey <zoey@z0ey.de>
@Zoey2936 Zoey2936 requested a review from szaimen March 4, 2026 20:57
ini_set('session.save_path', $dataConst->GetSessionDirectory());

// Auto logout on browser close
ini_set('session.cookie_lifetime', '0');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this since it is the default


$container = \AIO\DependencyInjection::GetContainer();
$dataConst = $container->get(\AIO\Data\DataConst::class);
ini_set('session.save_path', $dataConst->GetSessionDirectory());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to session_start

ini_set('session.cookie_lifetime', '0');

# Keep session for 24h max
ini_set('session.gc_maxlifetime', '86400');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to session_start

"use_strict_mode" => true,
"cookie_secure" => true,
"cookie_httponly" => true,
"cookie_samesite" => "Strict",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if Strict or Lax should be used. Lax works in any case. But strict should be perefferd, see here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie#samesitesamesite-value

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strict should work, so let's use that, please. I would consider anything that breaks using Strict a bug.

"gc_divisor" => 1,
"use_strict_mode" => true,
"cookie_secure" => true,
"cookie_httponly" => true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the browser/frontend never access the token with javascript this will make the token to be only send with https requests, while blocking javascript from reading it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since a short while we do fetch() some data from Javascript, so we need the cookie in JS, too, please.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you have a small missunderstanding here, even with httponly set, the cookie will still be sent for fetch request. httponly, only means that the js cannot read the cookie, it will still be sent for all matching http(s) requests truggered by js

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I wasn't concentrating. Sorry & thank you!

"gc_probability" => 1,
"gc_divisor" => 1,
"use_strict_mode" => true,
"cookie_secure" => true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes the cookie be only send over https, but not http

"gc_maxlifetime" => 86400,
"gc_probability" => 1,
"gc_divisor" => 1,
"use_strict_mode" => true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +42 to +44
"gc_maxlifetime" => 86400,
"gc_probability" => 1,
"gc_divisor" => 1,
Copy link
Collaborator Author

@Zoey2936 Zoey2936 Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the past only gc_maxlifetime was set. It controls after which time a session may be deleted. The comment said "Keep session for 24h max", but this is wrong. If only gc_maxlifetime is changed but not gc_probability/gc_divisor it only means that a session can be deleted after 24 hours with a chance of 1%. Setting gc_probability/gc_divisor both to 1 means that the session will be deleted to 100% after 24 hours

https://www.php.net/manual/en/session.configuration.php#ini.session.gc-probability

@szaimen szaimen added 2. developing Work in progress enhancement New feature or request technical debt labels Mar 6, 2026
@szaimen szaimen added this to the next milestone Mar 6, 2026
@szaimen szaimen requested a review from pabzm March 12, 2026 17:32
Copy link
Member

@pabzm pabzm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this contribution, highly appreciated! Please allow cookie access from Javascript, though, we need it to fetch log data.

Copy link
Member

@pabzm pabzm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much! 👍

Copy link
Collaborator

@szaimen szaimen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @Zoey2936!

One suggestion: can you please add the comments that you added in the review into the codebase so that we now directly what it does? Thanks in advance! :)

Signed-off-by: Zoey <zoey@z0ey.de>
@Zoey2936
Copy link
Collaborator Author

Thanks a lot @Zoey2936!

One suggestion: can you please add the comments that you added in the review into the codebase so that we now directly what it does? Thanks in advance! :)

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. developing Work in progress enhancement New feature or request technical debt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants