-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[Security] Fix SameSite cookie CSRF protection #7539
Conversation
1. The session variable that indicates to use it was set to "true". However, it should be a string indicating the value to use (either "strict" or "lax"). See: https://www.php.net/manual/en/session.configuration.php#ini.session.cookie-samesite 2. The use_strict_mode setting (See: https://www.php.net/manual/en/session.configuration.php#ini.session.use-strict-mode) in PHP is not enabled by default. This means that, even when logging out, the session_destroy/session_start procedure reuses the old cookie and does not set a new cookie with the proper samesite flag. All the PHP documentation I've seen says use_strict_mode should always be enabled, but defaults to disabled. This explicitly overrides the php.ini setting (default false) to set it at the beginning of the code, ensuring that NDB_Client properly generates a new session cookie.
@@ -132,8 +132,8 @@ class NDB_Client | |||
. $config_additions | |||
); | |||
// start php session | |||
$sessionOptions = array('cookie_httponly' => true); | |||
$sessionOptions['cookie_samesite'] = true; | |||
$sessionOptions = ['cookie_httponly' => true]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bracket style was changed here to avoid conflicts with main (main is using [
) when pulling this forward
// PHP documentation says this should always be enabled for session security. | ||
// PHP documentation says this is disabled by default. | ||
// Explicitly enable it. | ||
// phpcs:ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's any choice but to ignore the next line since the URL is so long
This fixes 2 issues related to the SameSite cookie CSRF protection:
However, it should be a string indicating the value to use (either
"strict" or "lax"). See: https://www.php.net/manual/en/session.configuration.php#ini.session.cookie-samesite
in PHP is not enabled by default. This means that, even when logging out, the
session_destroy/session_start procedure reuses the old cookie and does not set a new cookie with
the proper samesite flag. All the PHP documentation I've seen says use_strict_mode should always
be enabled, but defaults to disabled. This explicitly overrides the php.ini setting (default false)
to set it at the beginning of the code, ensuring that NDB_Client properly generates a new session cookie.