vendor/heimrichhannot/contao-ajax-bundle/src/Backend/Hooks.php line 19

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright (c) 2018 Heimrich & Hannot GmbH
  4.  *
  5.  * @license LGPL-3.0-or-later
  6.  */
  7. namespace HeimrichHannot\AjaxBundle\Backend;
  8. use Contao\System;
  9. use Symfony\Component\Security\Csrf\CsrfToken;
  10. class Hooks
  11. {
  12.     /**
  13.      * Contao initialize.php hook before request token validation happend.
  14.      */
  15.     public function initializeSystemHook()
  16.     {
  17.         if (System::getContainer()->get('huh.utils.container')->isBackend()) {
  18.             return;
  19.         }
  20.         if (!System::getContainer()->get('huh.request')->isXmlHttpRequest()) {
  21.             return;
  22.         }
  23.         // improved REQUEST_TOKEN handling within front end mode
  24.         if (System::getContainer()->get('huh.request')->isMethod('POST') && !System::getContainer()->get('security.csrf.token_manager')->isTokenValid(new CsrfToken(System::getContainer()->getParameter('contao.csrf_token_name'), System::getContainer()->get('huh.request')->getPost('REQUEST_TOKEN')))) {
  25.             System::getContainer()->get('huh.ajax')->setRequestTokenExpired();
  26.         }
  27.     }
  28. }