Fix: use CSRF token manager for Contao 5 request token
This commit is contained in:
@@ -25,7 +25,7 @@ class DummyCopierModule extends BackendModule
|
|||||||
$connection = System::getContainer()->get('database_connection');
|
$connection = System::getContainer()->get('database_connection');
|
||||||
|
|
||||||
$this->Template->action = Environment::get('request');
|
$this->Template->action = Environment::get('request');
|
||||||
$this->Template->requestToken = \defined('REQUEST_TOKEN') ? REQUEST_TOKEN : '';
|
$this->Template->requestToken = $this->getCsrfToken();
|
||||||
$this->Template->pageChoices = $this->getPageChoices($connection);
|
$this->Template->pageChoices = $this->getPageChoices($connection);
|
||||||
$this->Template->moduleChoices = $this->getModuleChoices($connection);
|
$this->Template->moduleChoices = $this->getModuleChoices($connection);
|
||||||
$this->Template->contentChoices = $this->getContentChoices($connection);
|
$this->Template->contentChoices = $this->getContentChoices($connection);
|
||||||
@@ -139,6 +139,26 @@ class DummyCopierModule extends BackendModule
|
|||||||
return $ids[0] ?? 0;
|
return $ids[0] ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getCsrfToken(): string
|
||||||
|
{
|
||||||
|
$container = System::getContainer();
|
||||||
|
|
||||||
|
// Contao 5: use Symfony CSRF token manager
|
||||||
|
if ($container->has('contao.csrf.token_manager')) {
|
||||||
|
return $container
|
||||||
|
->get('contao.csrf.token_manager')
|
||||||
|
->getToken((string) $container->getParameter('contao.csrf_token_name'))
|
||||||
|
->getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Contao 4 fallback
|
||||||
|
if (\defined('REQUEST_TOKEN')) {
|
||||||
|
return REQUEST_TOKEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<int,string>
|
* @return array<int,string>
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user