‪TYPO3CMS  10.4
ServerResponseCheckController.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
24 
30 {
31  public static function ‪hmac(string $value): string
32  {
33  return GeneralUtility::hmac($value, ServerResponseCheckController::class);
34  }
35 
36  public function ‪checkHostAction(ServerRequestInterface $request): ResponseInterface
37  {
38  $time = $request->getQueryParams()['src-time'] ?? null;
39  $hash = $request->getQueryParams()['src-hash'] ?? null;
40 
41  if (empty($time) || !is_string($time) || empty($hash) || !is_string($hash)) {
42  return new ‪JsonResponse(['error' => 'Query params src-time` and src-hash` are required.'], 400);
43  }
44  if (!hash_equals(self::hmac($time), $hash)) {
45  return new ‪JsonResponse(['error' => 'Invalid time or hash provided.'], 400);
46  }
47  if ((int)$time + 60 < time()) {
48  return new ‪JsonResponse(['error' => 'Request expired.'], 400);
49  }
50 
51  return new ‪JsonResponse([
52  'server.HTTP_HOST' => $_SERVER['HTTP_HOST'] ?? null,
53  'server.SERVER_NAME' => $_SERVER['SERVER_NAME'] ?? null,
54  'server.SERVER_PORT' => $_SERVER['SERVER_PORT'] ?? null,
55  ]);
56  }
57 }
‪TYPO3\CMS\Install\Controller\ServerResponseCheckController\hmac
‪static hmac(string $value)
Definition: ServerResponseCheckController.php:31
‪TYPO3\CMS\Install\Controller\ServerResponseCheckController\checkHostAction
‪checkHostAction(ServerRequestInterface $request)
Definition: ServerResponseCheckController.php:36
‪TYPO3\CMS\Install\Controller\ServerResponseCheckController
Definition: ServerResponseCheckController.php:30
‪TYPO3\CMS\Install\Controller
Definition: AbstractController.php:18
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46