mirror of
https://github.com/Studio-42/elFinder
synced 2026-06-08 12:37:09 +00:00
[php:session] fix #3017 param "SameSite=None" support for CORS
Allow arbitrary parameters to be added to the cookie in order to be able to set the “SameSite=None” parameter that will be required by CORS. ```php // session options $sessopts = array(); // Add 'SameSite=None' but exclude WebKit // see https://bugs.webkit.org/show_bug.cgi?id=198181 if (empty($_SERVER['HTTP_USER_AGENT']) || !preg_match('/(?:(?:iPhone OS|iPad; CPU OS) 1[0-2]|Mac OS X.*Version\/1[0-2].*Safari)/', $_SERVER['HTTP_USER_AGENT'])) { $sessopts['cookieParams'] = array('SameSite' => 'None'); } // elFinder options $opts = array( 'roots' => array( array( 'driver' => 'LocalFileSystem', 'path' => '/path/to/files/', 'URL' => 'http://localhost/to/files/', 'session' => new elFinderSession($sessopts) ) ) ); // run elFinder $connector = new elFinderConnector(new elFinder($opts)); $connector->run(); ```
This commit is contained in:
+11
-3
@@ -49,7 +49,8 @@ class elFinderSession implements elFinderSessionInterface
|
||||
'keys' => array(
|
||||
'default' => 'elFinderCaches',
|
||||
'netvolume' => 'elFinderNetVolumes'
|
||||
)
|
||||
),
|
||||
'cookieParams' => array()
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -64,7 +65,7 @@ class elFinderSession implements elFinderSessionInterface
|
||||
$this->opts = array_merge($this->opts, $opts);
|
||||
$this->base64encode = !empty($this->opts['base64encode']);
|
||||
$this->keys = $this->opts['keys'];
|
||||
if (function_exists('apache_get_version')) {
|
||||
if (function_exists('apache_get_version') || $this->opts['cookieParams']) {
|
||||
$this->fixCookieRegist = true;
|
||||
}
|
||||
|
||||
@@ -217,7 +218,14 @@ class elFinderSession implements elFinderSessionInterface
|
||||
if ($this->fixCookieRegist === true) {
|
||||
// regist cookie only once for apache2 SAPI
|
||||
$cParm = session_get_cookie_params();
|
||||
setcookie(session_name(), session_id(), 0, $cParm['path'], $cParm['domain'], $cParm['secure'], $cParm['httponly']);
|
||||
if ($this->opts['cookieParams'] && is_array($this->opts['cookieParams'])) {
|
||||
$cParm = array_merge($cParm, $this->opts['cookieParams']);
|
||||
}
|
||||
if (version_compare(PHP_VERSION, '7.3', '<')) {
|
||||
setcookie(session_name(), session_id(), 0, $cParm['path'] . (!empty($cParm['SameSite'])? '; SameSite=' . $cParm['SameSite'] : ''), $cParm['domain'], $cParm['secure'], $cParm['httponly']);
|
||||
} else {
|
||||
setcookie(session_name(), session_id(), $cParm);
|
||||
}
|
||||
$this->fixCookieRegist = false;
|
||||
}
|
||||
session_write_close();
|
||||
|
||||
Reference in New Issue
Block a user