Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security] Fix SameSite cookie CSRF protection #7539

Merged
merged 2 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions htdocs/AjaxHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
__DIR__ . "/../project/libraries:" .
__DIR__ . "/../php/libraries"
);
ini_set('session.use_strict_mode', '1');

require_once __DIR__ . "/../vendor/autoload.php";
// Ensures the user is logged in, and parses the config file.
Expand Down
7 changes: 7 additions & 0 deletions htdocs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
// to be done before NDB_Client starts the PHP session.)
session_cache_limiter("");

// 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

// See: https://www.php.net/manual/en/session.configuration.php#ini.session.use-strict-mode
ini_set('session.use_strict_mode', '1');

// FIXME: The code in NDB_Client should mostly be replaced by middleware.
$client = new \NDB_Client;
$client->initialize();
Expand Down
2 changes: 2 additions & 0 deletions htdocs/survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
set_include_path(get_include_path().":../project/libraries:../php/libraries:");
ini_set('default_charset', 'utf-8');
ini_set('session.use_strict_mode', '1');

require_once __DIR__ . "/../vendor/autoload.php";
require_once 'NDB_Config.class.inc';
require_once 'Smarty_hook.class.inc';
Expand Down
4 changes: 2 additions & 2 deletions php/libraries/NDB_Client.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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

$sessionOptions['cookie_samesite'] = "Strict";

// API Detect
if (strpos(
Expand Down