Skip to content

Commit

Permalink
Fix #237 - use the right cookie name and value for FE user login check
Browse files Browse the repository at this point in the history
  • Loading branch information
lochmueller committed Feb 11, 2020
1 parent 59706f7 commit 29d07c0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Classes/Middleware/FallbackMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use SFC\Staticfilecache\Cache\Rule\AbstractRule;
use SFC\Staticfilecache\Service\CacheService;
use SFC\Staticfilecache\Service\ConfigurationService;
use SFC\Staticfilecache\Service\CookieService;
use SFC\Staticfilecache\Service\ObjectFactoryService;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -66,7 +67,7 @@ protected function handleViaFallback(ServerRequestInterface $request): ResponseI
}
}

if (isset($_COOKIE['staticfilecache']) && $_COOKIE['staticfilecache'] === 'fe_typo_user_logged_in') {
if (isset($_COOKIE[CookieService::FE_COOKIE_NAME]) && $_COOKIE[CookieService::FE_COOKIE_NAME] === 'typo_user_logged_in') {
throw new \Exception('StaticFileCache Cookie is set', 12738912);
}

Expand Down
3 changes: 2 additions & 1 deletion Classes/Middleware/GenerateMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use SFC\Staticfilecache\Cache\UriFrontend;
use SFC\Staticfilecache\Service\CacheService;
use SFC\Staticfilecache\Service\ConfigurationService;
use SFC\Staticfilecache\Service\CookieService;
use SFC\Staticfilecache\Service\DateTimeService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
Expand Down Expand Up @@ -62,7 +63,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface

$uri = (string)$request->getUri();
if (!$response->hasHeader('X-SFC-Explanation')) {
if ($this->hasValidCacheEntry($uri) && !isset($_COOKIE['staticfilecache'])) {
if ($this->hasValidCacheEntry($uri) && !isset($_COOKIE[CookieService::FE_COOKIE_NAME])) {
$response = $response->withHeader('X-SFC-State', 'TYPO3 - already in cache');
return $this->removeSfcHeaders($response);
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Service/ClientService.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function getCallableClient(string $domain): Client
{
$jar = GeneralUtility::makeInstance(CookieJar::class);
$cookie = GeneralUtility::makeInstance(SetCookie::class);
$cookie->setName('staticfilecache');
$cookie->setName(CookieService::FE_COOKIE_NAME);
$cookie->setValue('1');
$cookie->setPath('/');
$cookie->setExpires((new DateTimeService())->getCurrentTime() + 3600);
Expand Down
2 changes: 1 addition & 1 deletion Documentation/Configuration/Nginx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ By the following configuration:
}
# We can't serve static files for logged-in BE/FE users
if ($cookie_staticfilecache = 'fe_typo_user_logged_in') {
if ($cookie_staticfilecache = 'typo_user_logged_in') {
return 405;
}
if ($cookie_be_typo_user != '') {
Expand Down

0 comments on commit 29d07c0

Please sign in to comment.