Skip to content

Commit a493dd6

Browse files
authored
Merge pull request dokuwiki#3994 from dokuwiki/cookie
Set SameSite=Lax Cookie Attribute and Upgrade Requirements to PHP 7.4
2 parents bbf8c24 + 486f82f commit a493dd6

29 files changed

+141
-179
lines changed

.github/workflows/testLinux.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
strategy:
2020
matrix:
21-
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
21+
php-versions: ['7.4', '8.0', '8.1', '8.2']
2222
fail-fast: false
2323

2424
services:

.github/workflows/testWindows.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
strategy:
2020
matrix:
21-
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
21+
php-versions: ['7.4', '8.0', '8.1', '8.2']
2222
fail-fast: false
2323

2424
steps:

_test/fetchphpunit.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
print "Running PHP $phpVersion\n";
99

1010

11-
if(version_compare($phpVersion, '7.2') < 0) {
12-
echo 'we no longer support PHP versions < 7.2 and thus do not support tests on them';
11+
if(version_compare($phpVersion, '7.4') < 0) {
12+
echo 'we no longer support PHP versions < 7.4 and thus do not support tests on them';
1313
exit(1);
1414
}
1515

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "project",
66
"license": "GPL v2",
77
"require": {
8-
"php": ">=7.2",
8+
"php": ">=7.4",
99
"ext-json": "*",
1010
"splitbrain/php-archive": "~1.0",
1111
"phpseclib/phpseclib": "~2.0",
@@ -21,7 +21,7 @@
2121
},
2222
"config": {
2323
"platform": {
24-
"php": "7.2"
24+
"php": "7.4"
2525
}
2626
},
2727
"suggest": {

composer.lock

+23-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

conf/dokuwiki.php

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
$conf['disableactions'] = ''; //comma separated list of actions to disable
6565
$conf['auth_security_timeout'] = 900; //time (seconds) auth data is considered valid, set to 0 to recheck on every page view
6666
$conf['securecookie'] = 1; //never send HTTPS cookies via HTTP
67+
$conf['samesitecookie'] = 'Lax'; //SameSite attribute for cookies (Lax|Strict|None|Empty)
6768
$conf['remote'] = 0; //Enable/disable remote interfaces
6869
$conf['remoteuser'] = '!!not set!!'; //user/groups that have access to remote interface (comma separated). leave empty to allow all users
6970
$conf['remotecors'] = ''; //enable Cross-Origin Resource Sharing (CORS) for the remote interfaces. Asterisk (*) to allow all origins. leave empty to deny.

inc/auth.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,13 @@ function auth_logoff($keepbc = false) {
429429
$USERINFO = null; //FIXME
430430

431431
$cookieDir = empty($conf['cookiedir']) ? DOKU_REL : $conf['cookiedir'];
432-
setcookie(DOKU_COOKIE, '', time() - 600000, $cookieDir, '', ($conf['securecookie'] && is_ssl()), true);
432+
setcookie(DOKU_COOKIE, '', [
433+
'expires' => time() - 600000,
434+
'path' => $cookieDir,
435+
'secure' => ($conf['securecookie'] && is_ssl()),
436+
'httponly' => true,
437+
'samesite' => $conf['samesitecookie'] ?: null, // null means browser default
438+
]);
433439

434440
if($auth) $auth->logOff();
435441
}
@@ -1256,7 +1262,13 @@ function auth_setCookie($user, $pass, $sticky) {
12561262
$cookie = base64_encode($user).'|'.((int) $sticky).'|'.base64_encode($pass);
12571263
$cookieDir = empty($conf['cookiedir']) ? DOKU_REL : $conf['cookiedir'];
12581264
$time = $sticky ? (time() + 60 * 60 * 24 * 365) : 0; //one year
1259-
setcookie(DOKU_COOKIE, $cookie, $time, $cookieDir, '', ($conf['securecookie'] && is_ssl()), true);
1265+
setcookie(DOKU_COOKIE, $cookie, [
1266+
'expires' => $time,
1267+
'path' => $cookieDir,
1268+
'secure' => ($conf['securecookie'] && is_ssl()),
1269+
'httponly' => true,
1270+
'samesite' => $conf['samesitecookie'] ?: null, // null means browser default
1271+
]);
12601272

12611273
// set session
12621274
$_SESSION[DOKU_COOKIE]['auth']['user'] = $user;

inc/common.php

+10-12
Original file line numberDiff line numberDiff line change
@@ -743,17 +743,10 @@ function checkwordblock($text = '') {
743743
// phpcs:enable
744744

745745
$wordblocks = getWordblocks();
746-
// how many lines to read at once (to work around some PCRE limits)
747-
if(version_compare(phpversion(), '4.3.0', '<')) {
748-
// old versions of PCRE define a maximum of parenthesises even if no
749-
// backreferences are used - the maximum is 99
750-
// this is very bad performancewise and may even be too high still
751-
$chunksize = 40;
752-
} else {
753-
// read file in chunks of 200 - this should work around the
754-
// MAX_PATTERN_SIZE in modern PCRE
755-
$chunksize = 200;
756-
}
746+
// read file in chunks of 200 - this should work around the
747+
// MAX_PATTERN_SIZE in modern PCRE
748+
$chunksize = 200;
749+
757750
while($blocks = array_splice($wordblocks, 0, $chunksize)) {
758751
$re = array();
759752
// build regexp from blocks
@@ -1952,7 +1945,12 @@ function set_doku_pref($pref, $val) {
19521945
if(defined('DOKU_UNITTEST')) {
19531946
$_COOKIE['DOKU_PREFS'] = $cookieVal;
19541947
}else{
1955-
setcookie('DOKU_PREFS', $cookieVal, time()+365*24*3600, $cookieDir, '', ($conf['securecookie'] && is_ssl()));
1948+
setcookie('DOKU_PREFS', $cookieVal, [
1949+
'expires' => time() + 365 * 24 * 3600,
1950+
'path' => $cookieDir,
1951+
'secure' => ($conf['securecookie'] && is_ssl()),
1952+
'samesite' => 'Lax'
1953+
]);
19561954
}
19571955
}
19581956

inc/infoutils.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,13 @@ function check(){
155155
if ($INFO['isadmin'] || $INFO['ismanager']){
156156
msg('DokuWiki version: '.getVersion(),1);
157157

158-
if(version_compare(phpversion(),'7.2.0','<')){
159-
msg('Your PHP version is too old ('.phpversion().' vs. 7.2+ needed)',-1);
158+
if(version_compare(phpversion(),'7.4.0','<')){
159+
msg('Your PHP version is too old ('.phpversion().' vs. 7.4+ needed)',-1);
160160
}else{
161161
msg('PHP version '.phpversion(),1);
162162
}
163163
} else {
164-
if(version_compare(phpversion(),'7.2.0','<')){
164+
if(version_compare(phpversion(),'7.4.0','<')){
165165
msg('Your PHP version is too old',-1);
166166
}
167167
}

inc/init.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,14 @@ function_exists('ob_gzhandler') &&
249249
function init_session() {
250250
global $conf;
251251
session_name(DOKU_SESSION_NAME);
252-
session_set_cookie_params(
253-
DOKU_SESSION_LIFETIME,
254-
DOKU_SESSION_PATH,
255-
DOKU_SESSION_DOMAIN,
256-
($conf['securecookie'] && is_ssl()),
257-
true
258-
);
252+
session_set_cookie_params([
253+
'lifetime' => DOKU_SESSION_LIFETIME,
254+
'path' => DOKU_SESSION_PATH,
255+
'domain' => DOKU_SESSION_DOMAIN,
256+
'secure' => ($conf['securecookie'] && is_ssl()),
257+
'httponly' => true,
258+
'samesite' => 'Lax',
259+
]);
259260

260261
// make sure the session cookie contains a valid session ID
261262
if(isset($_COOKIE[DOKU_SESSION_NAME]) && !preg_match('/^[-,a-zA-Z0-9]{22,256}$/', $_COOKIE[DOKU_SESSION_NAME])) {

install.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,8 @@ function check_functions()
574574
global $lang;
575575
$ok = true;
576576

577-
if (version_compare(phpversion(), '5.6.0', '<')) {
578-
$error[] = sprintf($lang['i_phpver'], phpversion(), '5.6.0');
577+
if (version_compare(phpversion(), '7.4.0', '<')) {
578+
$error[] = sprintf($lang['i_phpver'], phpversion(), '7.4.0');
579579
$ok = false;
580580
}
581581

lib/plugins/config/lang/en/lang.php

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
$lang['disableactions_rss'] = 'XML Syndication (RSS)';
107107
$lang['auth_security_timeout'] = 'Authentication Security Timeout (seconds)';
108108
$lang['securecookie'] = 'Should cookies set via HTTPS only be sent via HTTPS by the browser? Disable this option when only the login of your wiki is secured with SSL but browsing the wiki is done unsecured.';
109+
$lang['samesitecookie'] = 'The samesite cookie attribute to use. Leaving it empty will let the browser decide on the samesite policy.';
109110
$lang['remote'] = 'Enable the remote API system. This allows other applications to access the wiki via XML-RPC or other mechanisms.';
110111
$lang['remoteuser'] = 'Restrict remote API access to the comma separated groups or users given here. Leave empty to give access to everyone.';
111112
$lang['remotecors'] = 'Enable Cross-Origin Resource Sharing (CORS) for the remote interfaces. Asterisk (*) to allow all origins. Leave empty to deny CORS.';

lib/plugins/config/settings/config.metadata.php

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
);
159159
$meta['auth_security_timeout'] = array('numeric');
160160
$meta['securecookie'] = array('onoff');
161+
$meta['samesitecookie'] = array('multichoice','_choices' => array('','Lax','Strict','None'));
161162
$meta['remote'] = array('onoff','_caution' => 'security');
162163
$meta['remoteuser'] = array('string');
163164
$meta['remotecors'] = array('string', '_caution' => 'security');

vendor/composer/autoload_psr4.php

+1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
'splitbrain\\JSStrip\\' => array($vendorDir . '/splitbrain/php-jsstrip/src'),
1515
'phpseclib\\' => array($vendorDir . '/phpseclib/phpseclib/phpseclib'),
1616
'SimplePie\\' => array($vendorDir . '/simplepie/simplepie/src'),
17+
'IXR\\tests\\' => array($vendorDir . '/kissifrot/php-ixr/tests'),
1718
'IXR\\' => array($vendorDir . '/kissifrot/php-ixr/src'),
1819
);

vendor/composer/autoload_static.php

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class ComposerStaticInita19a915ee98347a0c787119619d2ff9b
3131
),
3232
'I' =>
3333
array (
34+
'IXR\\tests\\' => 10,
3435
'IXR\\' => 4,
3536
),
3637
);
@@ -68,6 +69,10 @@ class ComposerStaticInita19a915ee98347a0c787119619d2ff9b
6869
array (
6970
0 => __DIR__ . '/..' . '/simplepie/simplepie/src',
7071
),
72+
'IXR\\tests\\' =>
73+
array (
74+
0 => __DIR__ . '/..' . '/kissifrot/php-ixr/tests',
75+
),
7176
'IXR\\' =>
7277
array (
7378
0 => __DIR__ . '/..' . '/kissifrot/php-ixr/src',

0 commit comments

Comments
 (0)