getCookieParams()[BackendUserAuthentication::getCookieName()])) { $backendUserObject = $this->initializeBackendUser($request); } $GLOBALS['BE_USER'] = $backendUserObject; // Load specific dependencies which are necessary for a valid Backend User // like $GLOBALS['LANG'] for labels in the language of the BE User (so AdminPanel works) if ($backendUserObject !== null) { $GLOBALS['LANG'] = $this->languageServiceFactory->createFromUserPreferences($GLOBALS['BE_USER']); $this->setBackendUserAspect($GLOBALS['BE_USER']); if ($this->context->getPropertyFromAspect('backend.user', 'isLoggedIn', false) && (strtolower($request->getServerParams()['HTTP_CACHE_CONTROL'] ?? '') === 'no-cache' || strtolower($request->getServerParams()['HTTP_PRAGMA'] ?? '') === 'no-cache') ) { // Detecting if shift-reload has been clicked to disable caching if so. // This is only done if a backend user is logged in to prevent DoS-attacks for "casual" requests. $cacheInstruction = $request->getAttribute('frontend.cache.instruction', new CacheInstruction()); $cacheInstruction->disableCache('EXT:frontend: Logged in backend user forced reload disabled cache.'); $request = $request->withAttribute('frontend.cache.instruction', $cacheInstruction); } } $response = $handler->handle($request); // If, when building the response, the user is still available, then ensure that the headers are sent properly if ($this->context->getAspect('backend.user')->isLoggedIn()) { return $this->applyHeadersToResponse($response); } return $response; } /** * Creates the backend user object and returns it if a valid backend user is found. */ protected function initializeBackendUser(ServerRequestInterface $request): ?FrontendBackendUserAuthentication { // New backend user object $backendUserObject = GeneralUtility::makeInstance(FrontendBackendUserAuthentication::class); try { $backendUserObject->start($request); } catch (MfaRequiredException $e) { // Do nothing, as the user is not fully authenticated - has not // passed required multi-factor authentication - via the backend. return null; } if (!empty($backendUserObject->user['uid'])) { $this->setBackendUserAspect($backendUserObject, (int)$backendUserObject->user['workspace_id']); $backendUserObject->fetchGroupData(); } // Unset the user initialization if any setting / restriction applies if (!$this->isAuthenticated($backendUserObject, $request, $request->getAttribute('normalizedParams'))) { $backendUserObject = null; $this->setBackendUserAspect(null); } return $backendUserObject; } /** * Implementing the access checks that the TYPO3 CMS bootstrap script does before a user is ever logged in. * Returns TRUE if access is OK */ protected function isAuthenticated(FrontendBackendUserAuthentication $user, ServerRequestInterface $request, NormalizedParams $normalizedParams): bool { // Check IP $ipMask = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'] ?? ''); if ($ipMask && !GeneralUtility::cmpIP($normalizedParams->getRemoteAddress(), $ipMask)) { return false; } // Check SSL (https) if ($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'] && !$normalizedParams->isHttps()) { return false; } return $user->backendCheckLogin($request); } }