Skip to content

Commit 486f82f

Browse files
committed
add setting to define the samesite cookie policy
As mentioned in dokuwiki#3994 (review) there might be occasions when users might want to change the policy to a stricter one or the somewhat more lenient Lax implementation of current browsers.
1 parent 6425952 commit 486f82f

File tree

4 files changed

+5
-2
lines changed

4 files changed

+5
-2
lines changed

conf/dokuwiki.php

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ function auth_logoff($keepbc = false) {
434434
'path' => $cookieDir,
435435
'secure' => ($conf['securecookie'] && is_ssl()),
436436
'httponly' => true,
437-
'samesite' => 'Lax',
437+
'samesite' => $conf['samesitecookie'] ?: null, // null means browser default
438438
]);
439439

440440
if($auth) $auth->logOff();
@@ -1267,7 +1267,7 @@ function auth_setCookie($user, $pass, $sticky) {
12671267
'path' => $cookieDir,
12681268
'secure' => ($conf['securecookie'] && is_ssl()),
12691269
'httponly' => true,
1270-
'samesite' => 'Lax',
1270+
'samesite' => $conf['samesitecookie'] ?: null, // null means browser default
12711271
]);
12721272

12731273
// set session

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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');

0 commit comments

Comments
 (0)