Skip to content
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

Merged
merged 2 commits into from
Aug 19, 2021

Conversation

driusan
Copy link
Collaborator

@driusan driusan commented Aug 19, 2021

This fixes 2 issues related to the SameSite cookie CSRF protection:

  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.

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.
@driusan driusan added Security PR patches a vulnerability, makes resource access changes, or updates dependencies Bug PR or issue introducing/requiring bug fixes (not mutually exclusive with the Feature label) Priority: High PR or issue should be prioritised over others for review and testing labels Aug 19, 2021
@@ -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];
Copy link
Collaborator Author

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
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 don't think there's any choice but to ignore the next line since the URL is so long

@driusan driusan merged commit 13df539 into aces:23.0-release Aug 19, 2021
@ridz1208 ridz1208 added this to the 23.0.6 milestone Aug 19, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Bug PR or issue introducing/requiring bug fixes (not mutually exclusive with the Feature label) Priority: High PR or issue should be prioritised over others for review and testing Security PR patches a vulnerability, makes resource access changes, or updates dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants