Fix Cross Site Request Forgery on theme selection by using token

This commit is contained in:
Alejandro Romero Herrera 2020-08-24 23:15:29 +03:00
parent 916f7b7a16
commit 1b4eeb386a
2 changed files with 18 additions and 5 deletions

View file

@ -21,10 +21,23 @@ checkRole(array('admin'));
// ============================================================================
// Main after POST
// ============================================================================
$themeDirectory = $layout['parameters'];
$parameters = explode("/", $layout['parameters']);
if(count($parameters)==2) {
$themeDirectory = $parameters[0];
// Activate theme
activateTheme($themeDirectory);
// Verify CSRF Token
$token = Sanitize::html($parameters[1]);
if (!$security->validateTokenCSRF($token)) {
Log::set(__FILE__.LOG_SEP.'Error occurred when trying to validate the tokenCSRF.', ALERT_STATUS_FAIL);
Log::set(__FILE__.LOG_SEP.'Token in install theme ['.$token.']', ALERT_STATUS_FAIL);
Session::destroy();
Redirect::page('login');
} else {
// Activate theme
activateTheme($themeDirectory);
}
}
// Redirect
Redirect::page('themes');

View file

@ -24,7 +24,7 @@ foreach ($themes as $theme) {
';
if ($theme['dirname']!=$site->theme()) {
echo '<a href="'.HTML_PATH_ADMIN_ROOT.'install-theme/'.$theme['dirname'].'">'.$L->g('Activate').'</a>';
echo '<a href="'.HTML_PATH_ADMIN_ROOT.'install-theme/'.$theme['dirname'].'/'.$security->getTokenCSRF().'">'.$L->g('Activate').'</a>';
}
echo '
@ -50,4 +50,4 @@ foreach ($themes as $theme) {
echo '
</tbody>
</table>
';
';