diff --git a/src/config-sample.php b/src/config-sample.php index a6d530bc7..eb9a5cdbf 100644 --- a/src/config-sample.php +++ b/src/config-sample.php @@ -185,6 +185,13 @@ return [ // How many login requests allowed per time span 'rate_limit_login' => 20, + + /* + * This enables the usage of a token to protect the system from CSRF attacks. + * Disabling this is highly discouraged and opens your instance to a known vulnerability. + * This option is only here for backwards compatibility. + */ + 'CSRFPrevention' => true, ], 'guzzle' => [ diff --git a/src/install/install.php b/src/install/install.php index 158233fdb..6882f01af 100644 --- a/src/install/install.php +++ b/src/install/install.php @@ -462,6 +462,7 @@ final class Box_Installer 'throttle_delay' => 2, 'rate_span_login' => 60, 'rate_limit_login' => 20, + 'CSRFPrevention' => true, ], 'guzzle' => [ 'user_agent' => 'Mozilla/5.0 (RedHatEnterpriseLinux; Linux x86_64; FOSSBilling; +http://fossbilling.org) Gecko/20100101 Firefox/93.0', diff --git a/src/library/Box/AppAdmin.php b/src/library/Box/AppAdmin.php index 36f2f1a2b..a5056e47b 100644 --- a/src/library/Box/AppAdmin.php +++ b/src/library/Box/AppAdmin.php @@ -54,6 +54,10 @@ class Box_AppAdmin extends Box_App $twig->setLoader($loader); $twig->addGlobal('theme', $theme); + + //CSRF token + $token = (!is_null(session_id())) ? hash('md5', session_id()) : null; + $twig->addGlobal('CSRFToken', $token); if ($this->di['auth']->isAdminLoggedIn()) { $twig->addGlobal('admin', $this->di['api_admin']); diff --git a/src/library/Box/AppClient.php b/src/library/Box/AppClient.php index 63f49bc3e..3d3af6cb8 100644 --- a/src/library/Box/AppClient.php +++ b/src/library/Box/AppClient.php @@ -104,6 +104,10 @@ class Box_AppClient extends Box_App $twig->addGlobal('current_theme', $code); $twig->addGlobal('settings', $settings); + //CSRF token + $token = (!is_null(session_id())) ? hash('md5', session_id()) : null; + $twig->addGlobal('CSRFToken', $token); + if ($this->di['auth']->isClientLoggedIn()) { $twig->addGlobal('client', $this->di['api_client']); } diff --git a/src/library/Box/Tools.php b/src/library/Box/Tools.php index cf700524e..4d6f7711b 100644 --- a/src/library/Box/Tools.php +++ b/src/library/Box/Tools.php @@ -527,6 +527,7 @@ class Box_Tools 'throttle_delay' => (isset($currentConfig['api']['rate_limit'])) ? $currentConfig['api']['rate_limit'] : 2, 'rate_span_login' => (isset($currentConfig['api']['rate_span_login'])) ? $currentConfig['api']['rate_span_login'] : 60, 'rate_limit_login' => (isset($currentConfig['api']['rate_limit_login'])) ? $currentConfig['api']['rate_limit_login'] : 20, + 'CSRFPrevention' => (isset($currentConfig['api']['CSRFPrevention'])) ? $currentConfig['api']['CSRFPrevention'] : true, ], 'guzzle' => [ 'user_agent' => (isset($currentConfig['guzzle']['user_agent'])) ? $currentConfig['guzzle']['user_agent'] : 'Mozilla/5.0 (RedHatEnterpriseLinux; Linux x86_64; FOSSBilling; +http://fossbilling.org) Gecko/20100101 Firefox/93.0', diff --git a/src/modules/Activity/html_admin/mod_activity_index.html.twig b/src/modules/Activity/html_admin/mod_activity_index.html.twig index 2f4d01316..4b6045558 100644 --- a/src/modules/Activity/html_admin/mod_activity_index.html.twig +++ b/src/modules/Activity/html_admin/mod_activity_index.html.twig @@ -63,7 +63,7 @@