ensureLoginRateLimit($frontendUser, $request); // Authenticate now $frontendUser->start($request); // no matter if we have an active user we try to fetch matching groups which can // be set without an user (simulation for instance!) $frontendUser->fetchGroupData($request); // Register the frontend user as aspect and within the request $this->context->setAspect('frontend.user', $frontendUser->createUserAspect()); $request = $request->withAttribute('frontend.user', $frontendUser); if ($this->context->getAspect('frontend.user')->isLoggedIn() && $rateLimiter) { $rateLimiter->reset(); $this->eventDispatcher->dispatch(new AfterUserLoggedInEvent($frontendUser, $request)); } $response = $handler->handle($request); // Store session data for fe_users $frontendUser->storeSessionData(); $response = $frontendUser->appendCookieToResponse($response, $request->getAttribute('normalizedParams')); // Collect garbage in Frontend requests, which aren't fully cacheable (e.g. with cookies) if ($response->hasHeader('Set-Cookie')) { $this->sessionGarbageCollection(); } return $response; } /** * Garbage collection for fe_sessions (with a probability) */ protected function sessionGarbageCollection(): void { UserSessionManager::create('FE')->collectGarbage(); } protected function ensureLoginRateLimit(FrontendUserAuthentication $user, ServerRequestInterface $request): ?LimiterInterface { if (!$user->isActiveLogin($request)) { return null; } $loginRateLimiter = $this->rateLimiterFactory->createLoginRateLimiter($request, $user->loginType); $limit = $loginRateLimiter->consume(); if (!$limit->isAccepted()) { $this->logger->debug('Login request has been rate limited for IP address {ipAddress}', ['ipAddress' => $request->getAttribute('normalizedParams')->getRemoteAddress()]); $dateformat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm']; $lockedUntil = $limit->getRetryAfter()->getTimestamp() > 0 ? ' until ' . date($dateformat, $limit->getRetryAfter()->getTimestamp()) : ''; throw new RequestRateLimitedException( HttpUtility::HTTP_STATUS_403, 'The login is locked' . $lockedUntil . ' due to too many failed login attempts from your IP address.', 'Login Request Rate Limited', 1616175847 ); } return $loginRateLimiter; } }