Skip to content

Commit

Permalink
Merge pull request #58 from mediaessenz/v13-compat
Browse files Browse the repository at this point in the history
Add TYPO3 13 compatibility
  • Loading branch information
bmack authored Nov 15, 2024
2 parents ec0d529 + 9060fb6 commit d18dd34
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 387 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ jobs:
fast_finish: true
include:
- stage: test
php: 7.2
env: TYPO3=^8.7
php: 8.2
env: TYPO3=^12.4
- stage: test
php: 7.2
env: TYPO3=^9.5
php: 8.2
env: TYPO3=^13.4

- stage: publish to ter
if: tag IS present
php: 7.2
php: 8.2
before_install: skip
install: skip
before_script: skip
Expand Down
222 changes: 0 additions & 222 deletions Classes/JumpUrlProcessor.php

This file was deleted.

48 changes: 35 additions & 13 deletions Classes/Middleware/JumpUrlHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Http\RedirectResponse;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Resource\Security\FileNameValidator;
use TYPO3\CMS\Core\Site\Entity\NullSite;
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
use TYPO3\CMS\Core\TypoScript\PageTsConfig;
use TYPO3\CMS\Core\TypoScript\PageTsConfigFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

Expand Down Expand Up @@ -69,7 +73,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
}
// Regular jump URL
$this->validateIfJumpUrlRedirectIsAllowed($jumpUrl, $juHash);
return $this->redirectToJumpUrl($jumpUrl);
return $this->redirectToJumpUrl($jumpUrl, $request);
}
return $handler->handle($request);
}
Expand All @@ -81,9 +85,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
* @throws \Exception
* @return ResponseInterface
*/
protected function redirectToJumpUrl(string $jumpUrl): ResponseInterface
protected function redirectToJumpUrl(string $jumpUrl, ServerRequestInterface $request): ResponseInterface
{
$pageTSconfig = $this->getTypoScriptFrontendController()->getPagesTSconfig();
$pageTSconfig = $this->getPageTsConfig($request);
$pageTSconfig = array_key_exists('TSFE.', $pageTSconfig) && is_array($pageTSconfig['TSFE.'] ?? false) ? $pageTSconfig['TSFE.'] : [];

// Allow sections in links
Expand All @@ -94,6 +98,30 @@ protected function redirectToJumpUrl(string $jumpUrl): ResponseInterface
return new RedirectResponse($jumpUrl, $statusCode);
}

/**
* @param ServerRequestInterface $request
* @return array
* @throws \JsonException
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/
protected function getPageTsConfig(ServerRequestInterface $request): array
{
$pageInformation = $request->getAttribute('frontend.page.information');
$id = $pageInformation->getId();
$runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime');
$pageTsConfig = $runtimeCache->get('pageTsConfig-' . $id);
if ($pageTsConfig instanceof PageTsConfig) {
return $pageTsConfig->getPageTsConfigArray();
}
$fullRootLine = $pageInformation->getRootLine();
ksort($fullRootLine);
$site = $request->getAttribute('site') ?? new NullSite();
$pageTsConfigFactory = GeneralUtility::makeInstance(PageTsConfigFactory::class);
$pageTsConfig = $pageTsConfigFactory->create($fullRootLine, $site);
$runtimeCache->set('pageTsConfig-' . $id, $pageTsConfig);
return $pageTsConfig->getPageTsConfigArray();
}

/**
* If the submitted hash is correct and the user has access to the
* related content element the contents of the submitted file will
Expand Down Expand Up @@ -126,15 +154,9 @@ protected function forwardJumpUrlSecureFileData(string $jumpUrl, string $locatio

// Check if requested file accessable
$fileAccessAllowed = false;
if ((new Typo3Version())->getMajorVersion() < 11) {
$fileAccessAllowed = GeneralUtility::isAllowedAbsPath($absoluteFileName)
&& GeneralUtility::verifyFilenameAgainstDenyPattern($absoluteFileName)
&& !GeneralUtility::isFirstPartOfStr($absoluteFileName, Environment::getLegacyConfigPath());
} else {
$fileAccessAllowed = GeneralUtility::isAllowedAbsPath($absoluteFileName)
&& GeneralUtility::makeInstance(FileNameValidator::class)->isValid($absoluteFileName)
&& !str_starts_with($absoluteFileName, Environment::getLegacyConfigPath());
}
$fileAccessAllowed = GeneralUtility::isAllowedAbsPath($absoluteFileName)
&& GeneralUtility::makeInstance(FileNameValidator::class)->isValid($absoluteFileName)
&& !str_starts_with($absoluteFileName, Environment::getLegacyConfigPath());
if (!$fileAccessAllowed) {
throw new \Exception('The requested file was not allowed to be accessed through Jump URL. The path or file is not allowed.', 1294585194);
}
Expand All @@ -157,7 +179,7 @@ protected function forwardJumpUrlSecureFileData(string $jumpUrl, string $locatio
protected function isLocationDataValid(string $locationData): bool
{
$isValidLocationData = false;
list($pageUid, $table, $recordUid) = explode(':', $locationData);
[$pageUid, $table, $recordUid] = explode(':', $locationData);
$pageRepository = $this->getTypoScriptFrontendController()->sys_page;
if (empty($table) || $pageRepository->checkRecord($table, $recordUid, true)) {
// This check means that a record is checked only if the locationData has a value for a
Expand Down
Loading

0 comments on commit d18dd34

Please sign in to comment.