mirror of
https://github.com/Studio-42/elFinder
synced 2026-06-08 12:37:09 +00:00
fix(connector): refine CSRF token refresh timing and protected commands
- refresh CSRF TTL after successful open/info/protected commands - extend token lifetime on open requests during normal navigation - limit CSRF protection to stable write commands - fix callback script syntax in OAuth popup handling
This commit is contained in:
@@ -4212,7 +4212,7 @@ class elFinder
|
||||
$origin = isset($_SERVER['HTTP_ORIGIN'])? str_replace('\'', '\\\'', $_SERVER['HTTP_ORIGIN']) : '*';
|
||||
$script .= '
|
||||
var go = function() {
|
||||
var w = window.opener || window.parent || window,
|
||||
var w = window.opener || window.parent || window;
|
||||
var closeWindow = function(){
|
||||
try {
|
||||
window.close();
|
||||
|
||||
@@ -79,13 +79,10 @@ class elFinderConnector
|
||||
protected static $csrfProtectedCmds = array(
|
||||
'archive' => true,
|
||||
'chmod' => true,
|
||||
'dim' => true,
|
||||
'duplicate' => true,
|
||||
'editor' => true,
|
||||
'extract' => true,
|
||||
'mkdir' => true,
|
||||
'mkfile' => true,
|
||||
'netmount' => true,
|
||||
'paste' => true,
|
||||
'put' => true,
|
||||
'rename' => true,
|
||||
@@ -147,7 +144,10 @@ class elFinderConnector
|
||||
*/
|
||||
protected function shouldRefreshCsrfToken($cmd, array $src)
|
||||
{
|
||||
return ($cmd === 'info' && !empty($src['reload']));
|
||||
return (
|
||||
($cmd === 'info' && !empty($src['reload']))
|
||||
|| $cmd === 'open'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -373,10 +373,6 @@ class elFinderConnector
|
||||
$this->output(array('error' => $this->elFinder->error(elFinder::ERROR_UNKNOWN_CMD)));
|
||||
}
|
||||
|
||||
if ($this->shouldRefreshCsrfToken($cmd, $src)) {
|
||||
$this->refreshCsrfTokenTtl();
|
||||
}
|
||||
|
||||
if ($this->csrfProtectedCommand($cmd)) {
|
||||
if (!$this->validateCsrfToken()) {
|
||||
$this->outputCsrfError();
|
||||
@@ -415,8 +411,12 @@ class elFinderConnector
|
||||
|
||||
try {
|
||||
$result = $this->elFinder->exec($cmd, $args);
|
||||
if ($this->shouldIssueCsrfToken($cmd, $src) && is_array($result) && !isset($result['error'])) {
|
||||
$result[self::$csrfResponseKey] = $this->issueCsrfToken();
|
||||
if (is_array($result) && !isset($result['error'])) {
|
||||
if ($this->shouldIssueCsrfToken($cmd, $src)) {
|
||||
$result[self::$csrfResponseKey] = $this->issueCsrfToken();
|
||||
} else if ($this->shouldRefreshCsrfToken($cmd, $src)) {
|
||||
$this->refreshCsrfTokenTtl();
|
||||
}
|
||||
}
|
||||
$this->output($result);
|
||||
} catch (elFinderAbortException $e) {
|
||||
|
||||
Reference in New Issue
Block a user